Skip to content
TypeScript

feat(web,mobile): the @ picker lists threads on linked machines (#26201)

Julius Marminge4ab7084aa7fb
diff --git a/apps/mobile/src/components/ComposerEditor.tsx b/apps/mobile/src/components/ComposerEditor.tsx
index c96e872fd69..59c0a74e452 100644
--- a/apps/mobile/src/components/ComposerEditor.tsx
+++ b/apps/mobile/src/components/ComposerEditor.tsx
@@ -27,6 +27,7 @@ import { startComposerDraftOperation } from "../state/composerDraftOperations";
import { appAtomRegistry } from "../state/atom-registry";
import { mobilePreferencesAtom } from "../state/preferences";
import { useOpenLinkedThread } from "../features/threads/useOpenLinkedThread";
+import { useLinkedEnvironments } from "../state/peerLinks";
import { ComposerContextSheet } from "./ComposerContextSheet";
import { AppText as Text } from "./ui/AppText";
import {
@@ -77,6 +78,7 @@ export function ComposerEditor({
const [selected, setSelected] = useState<{ source: string; start: number; end: number } | null>(
null,
);
+ const linkedEnvironments = useLinkedEnvironments(environmentId ?? null);
const contextImports = useAtomValue(composerContextImportsAtom);
const importing = draftKey ? contextImports[draftKey] === true : false;
const pasteContext = async (
@@ -101,6 +103,7 @@ export function ComposerEditor({
signal,
retained.context?.records.length ?? 0,
environmentId,
+ linkedEnvironments,
);
if (signal.aborted) return;
if (!result) {
diff --git a/apps/mobile/src/features/threads/NewTaskDraftScreen.tsx b/apps/mobile/src/features/threads/NewTaskDraftScreen.tsx
index 0eea8b24e75..a21fcf039ac 100644
--- a/apps/mobile/src/features/threads/NewTaskDraftScreen.tsx
+++ b/apps/mobile/src/features/threads/NewTaskDraftScreen.tsx
@@ -625,6 +625,7 @@ export function NewTaskDraftScreen(props: {
text: draft.text,
records: draft.context?.records ?? [],
environmentId: selectedProject.environmentId,
+ linkedEnvironments: flow.linkedEnvironments,
})[0];
if (strandedThread) {
const owner =
diff --git a/apps/mobile/src/features/threads/ThreadComposer.tsx b/apps/mobile/src/features/threads/ThreadComposer.tsx
index 54e142d6623..d6c2eed0c17 100644
--- a/apps/mobile/src/features/threads/ThreadComposer.tsx
+++ b/apps/mobile/src/features/threads/ThreadComposer.tsx
@@ -67,6 +67,7 @@ import { appAtomRegistry } from "../../state/atom-registry";
import type { ComposerDocumentAttachment } from "../../lib/composerContext";
import { useProject, useThreadShells } from "../../state/entities";
import { useMentionableEnvironments } from "../../state/environments";
+import { useLinkedEnvironments } from "../../state/peerLinks";
import { scopeProjectRef } from "@t3tools/client-runtime/environment";
import { AppText as Text } from "../../components/ui/AppText";
@@ -536,6 +537,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
environments: offersLinkedEnvironments(props.serverConfig)
? mentionableEnvironments
: NO_MACHINES,
+ linkedEnvironments: useLinkedEnvironments(props.environmentId),
currentThreadId: props.selectedThread.id,
projectCwd: props.projectCwd,
pullRequestProjectId: props.serverConfig?.environment.capabilities.pullRequests
diff --git a/apps/mobile/src/features/threads/new-task-flow-provider.tsx b/apps/mobile/src/features/threads/new-task-flow-provider.tsx
index 06cb9c1f970..589d03b6b56 100644
--- a/apps/mobile/src/features/threads/new-task-flow-provider.tsx
+++ b/apps/mobile/src/features/threads/new-task-flow-provider.tsx
@@ -36,6 +36,7 @@ import { scopedProjectKey } from "../../lib/scopedEntities";
import { useAtomValue } from "@effect/atom-react";
import { appAtomRegistry } from "../../state/atom-registry";
import { projectEnvironment } from "../../state/projects";
+import { useLinkedEnvironments } from "../../state/peerLinks";
import { useEnvironmentQuery } from "../../state/query";
import { useAtomCommand } from "../../state/use-atom-command";
import {
@@ -160,6 +161,8 @@ type NewTaskFlowContextValue = {
readonly environmentLabel: string;
}>;
readonly selectedProject: EnvironmentProject | null;
+ /** The machines the selected project's environment links to, whose threads it can read. */
+ readonly linkedEnvironments: ReadonlyMap<EnvironmentId, string>;
readonly isScratchDraft: boolean;
readonly modelOptions: ReadonlyArray<ModelOption>;
readonly selectedModel: ModelSelection | null;
@@ -321,6 +324,7 @@ export function NewTaskFlowProvider(
projectsForEnvironment[0] ??
null);
+ const linkedEnvironments = useLinkedEnvironments(selectedProject?.environmentId ?? null);
const projectDefaults = useNewTaskProjectDefaults(selectedProject);
const selectedEnvironmentServerConfig = projectDefaults.serverConfig;
const isScratchDraft = projectDefaults.isScratch;
@@ -779,6 +783,7 @@ export function NewTaskFlowProvider(
text: draft.text,
records: draft.context?.records ?? [],
environmentId: selectedProject.environmentId,
+ linkedEnvironments,
}).length > 0
) {
return null;
@@ -853,6 +858,7 @@ export function NewTaskFlowProvider(
expandedProvider,
environments,
selectedProject,
+ linkedEnvironments,
isScratchDraft,
modelOptions,
selectedModel,
diff --git a/apps/mobile/src/features/threads/use-composer-command-menu.ts b/apps/mobile/src/features/threads/use-composer-command-menu.ts
index 493de489a3c..28ee640fa6e 100644
--- a/apps/mobile/src/features/threads/use-composer-command-menu.ts
+++ b/apps/mobile/src/features/threads/use-composer-command-menu.ts
@@ -16,6 +16,7 @@ import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/model
const EMPTY_THREAD_SHELLS: ReadonlyArray<EnvironmentThreadShell> = [];
const EMPTY_ENVIRONMENTS: ReadonlyArray<ComposerEnvironmentCandidate> = [];
+const NO_LINKED_ENVIRONMENTS: ReadonlyMap<EnvironmentId, string> = new Map();
import { COMPOSER_CONTEXT_MAX_RECORDS } from "@t3tools/contracts";
import { formatComposerContextReference } from "@t3tools/shared/composerContextReferences";
import {
@@ -211,6 +212,7 @@ export function useComposerCommandMenu({
environmentId,
threadShells = EMPTY_THREAD_SHELLS,
environments = EMPTY_ENVIRONMENTS,
+ linkedEnvironments = NO_LINKED_ENVIRONMENTS,
currentThreadId = null,
projectCwd,
pullRequestProjectId = null,
@@ -230,6 +232,8 @@ export function useComposerCommandMenu({
readonly environmentId: EnvironmentId | null;
readonly threadShells?: ReadonlyArray<EnvironmentThreadShell>;
readonly environments?: ReadonlyArray<ComposerEnvironmentCandidate>;
+ /** The machines `environmentId` links to, by name, whose threads the picker also offers. */
+ readonly linkedEnvironments?: ReadonlyMap<EnvironmentId, string>;
readonly currentThreadId?: ThreadId | null;
readonly projectCwd: string | null;
readonly pullRequestProjectId?: ProjectId | null;
@@ -459,6 +463,7 @@ export function useComposerCommandMenu({
? matchComposerThreadItems({
shells: threadShells,
environmentId,
+ linkedEnvironments,
excludeThreadId: currentThreadId,
query: trigger.query,
now,
diff --git a/apps/mobile/src/lib/composerContextClipboard.test.ts b/apps/mobile/src/lib/composerContextClipboard.test.ts
index d5701569ce8..afabd7afb55 100644
--- a/apps/mobile/src/lib/composerContextClipboard.test.ts
+++ b/apps/mobile/src/lib/composerContextClipboard.test.ts
@@ -295,6 +295,22 @@ describe("mobile context clipboard imports", () => {
expect(result!.text).toMatch(/^Compare these findings: .* before changing anything\.$/);
});
+ it("keeps a thread from a machine the destination links to", async () => {
+ const result = await importComposerContextClipboard(
+ mixedClipboard,
+ 0,
+ new AbortController().signal,
+ 0,
+ EnvironmentId.make("destination"),
+ new Map([[foreignThread.environmentId, "Source"]]),
+ );
+ expect(result!.skippedThreads).toEqual([]);
+ expect(result!.context.records.filter((record) => record.kind === "thread")).toEqual([
+ { ...foreignThread, contextId: expect.any(String) },
+ { ...localThread, contextId: expect.any(String) },
+ ]);
+ });
+
it("preserves both machines' thread references when pasting without a destination", async () => {
const result = await importComposerContextClipboard(
mixedClipboard,
diff --git a/apps/mobile/src/lib/composerContextClipboard.ts b/apps/mobile/src/lib/composerContextClipboard.ts
index 624233a12dd..e7c72018405 100644
--- a/apps/mobile/src/lib/composerContextClipboard.ts
+++ b/apps/mobile/src/lib/composerContextClipboard.ts
@@ -67,6 +67,8 @@ export async function importComposerContextClipboard(
signal: AbortSignal,
existingContextCount = 0,
destinationEnvironmentId?: EnvironmentId,
+ /** The machines the destination links to, whose threads its agent can read too. */
+ linkedEnvironments: ReadonlyMap<EnvironmentId, string> = new Map(),
) {
const fragment =
decodeComposerContextFragment(input.fragment) ?? decodeComposerContextClipboardHtml(input.html);
@@ -80,6 +82,7 @@ export async function importComposerContextClipboard(
text: imported.text,
records: imported.context.records,
environmentId: destinationEnvironmentId,
+ linkedEnvironments,
});
const skippedIds = new Set(skippedThreads.map((record) => record.contextId));
const retained = imported.context.records.filter((record) => !skippedIds.has(record.contextId));
diff --git a/apps/mobile/src/state/peerLinks.ts b/apps/mobile/src/state/peerLinks.ts
index bdcc66e3205..d29b6b39e9a 100644
--- a/apps/mobile/src/state/peerLinks.ts
+++ b/apps/mobile/src/state/peerLinks.ts
@@ -1,5 +1,9 @@
import { useAtomValue } from "@effect/atom-react";
-import { linkableMachines } from "@t3tools/client-runtime/link-request";
+import {
+ linkableMachines,
+ linkedEnvironmentNames,
+ offersLinkedEnvironments,
+} from "@t3tools/client-runtime/link-request";
import { createPeerLinkEnvironmentAtoms } from "@t3tools/client-runtime/state/peerLinks";
import type { EnvironmentId } from "@t3tools/contracts";
import { useEffect, useEffectEvent, useMemo } from "react";
@@ -12,6 +16,29 @@ import { useAtomCommand } from "./use-atom-command";
export const peerLinkEnvironment = createPeerLinkEnvironmentAtoms(connectionAtomRuntime);
+/**
+ * The machines `environmentId` links to, by name, while it offers links, and none otherwise.
+ * Its agents can read threads there. Listing asks each linked machine whether it answers, so
+ * every caller shares one briefly cached list.
+ */
+export function useLinkedEnvironments(
+ environmentId: EnvironmentId | null,
+): ReadonlyMap<EnvironmentId, string> {
+ const { environments } = useEnvironments();
+ const offered = offersLinkedEnvironments(
+ environments.find((environment) => environment.environmentId === environmentId)?.serverConfig,
+ );
+ const links = useEnvironmentQuery(
+ offered && environmentId !== null
+ ? peerLinkEnvironment.list({ environmentId, input: {} })
+ : null,
+ );
+ return useMemo(
+ () => linkedEnvironmentNames({ links: offered ? (links.data?.links ?? []) : [], environments }),
+ [environments, links.data, offered],
+ );
+}
+
/**
* The user's other machines, for picking one to link `environmentId` to,
* including those only on their T3 Connect account. Reads that environment's
diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsx
index 71a93bf86b2..9e70a44fb64 100644
--- a/apps/web/src/components/chat/ChatComposer.tsx
+++ b/apps/web/src/components/chat/ChatComposer.tsx
@@ -176,6 +176,7 @@ import {
import { rememberCopiedComposerAttachments } from "~/lib/copiedComposerAttachments";
import { useThreadContextDrop, threadContextDropTargetProps } from "./threadContextDrag";
import { readThreadShell } from "~/state/entities";
+import { useLinkedEnvironments } from "~/state/peerLinks";
import { encodeComposerContextFragment } from "@t3tools/shared/composerContextClipboard";
import type { ComposerContextRecord, ThreadPullRequestLink } from "@t3tools/contracts";
import { threadContextAttachment } from "~/lib/threadContextAttachment";
@@ -1147,6 +1148,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
composerTerminalContexts.length === 0 &&
composerPreviewAnnotations.length === 0 &&
composerReviewComments.length === 0;
+ const linkedEnvironments = useLinkedEnvironments(environmentId);
const {
items: composerMenuItems,
isLoading: isComposerMenuLoading,
@@ -1154,6 +1156,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
} = useComposerMenuItems({
composerTrigger,
environmentId,
+ linkedEnvironments,
gitCwd,
activeThreadId,
pullRequestProjectId,
@@ -1387,6 +1390,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
importContextFragmentStable,
} = useComposerContextImport({
environmentId,
+ linkedEnvironments,
activeThread,
activeThreadId,
composerDraftTarget,
@@ -2879,7 +2883,9 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
useThreadContextDrop(composerFormRef, environmentId, attachmentTargetKey, (refs, isActive) => {
const records = refs.flatMap((ref) => {
- if (ref.environmentId !== environmentId) {
+ // The agent reads a linked machine's thread itself, like the `@` picker's; any other
+ // machine's comes in as its transcript.
+ if (ref.environmentId !== environmentId && !linkedEnvironments.has(ref.environmentId)) {
void importDroppedThread(
ref,
() => isActive() && attachmentTargetKeyRef.current === attachmentTargetKey,
diff --git a/apps/web/src/components/chat/useComposerContextImport.ts b/apps/web/src/components/chat/useComposerContextImport.ts
index 56687662844..e859e816074 100644
--- a/apps/web/src/components/chat/useComposerContextImport.ts
+++ b/apps/web/src/components/chat/useComposerContextImport.ts
@@ -75,6 +75,7 @@ async function downloadAttachmentBlob(url: string): Promise<Blob | null> {
*/
export function useComposerContextImport(input: {
readonly environmentId: EnvironmentId;
+ readonly linkedEnvironments: ReadonlyMap<EnvironmentId, string>;
readonly activeThread: ChatComposerProps["activeThread"];
readonly activeThreadId: ChatComposerProps["activeThreadId"];
readonly composerDraftTarget: ChatComposerProps["composerDraftTarget"];
@@ -91,6 +92,7 @@ export function useComposerContextImport(input: {
}) {
const {
environmentId,
+ linkedEnvironments,
activeThread,
activeThreadId,
composerDraftTarget,
@@ -372,8 +374,13 @@ export function useComposerContextImport(input: {
break;
}
case "thread": {
- // The agent can only read threads on its own server; a pasted foreign one is dropped.
- if (record.environmentId !== environmentId) break;
+ // The agent reads threads on its own server and the machines it links to; a pasted
+ // thread from any other machine is dropped.
+ if (
+ record.environmentId !== environmentId &&
+ !linkedEnvironments.has(record.environmentId)
+ )
+ break;
addComposerDraftThreadContexts(threadDraftTarget, [record], {
appendReference: false,
});
diff --git a/apps/web/src/components/chat/useComposerMenuItems.ts b/apps/web/src/components/chat/useComposerMenuItems.ts
index 26486cc266b..d9e11c53226 100644
--- a/apps/web/src/components/chat/useComposerMenuItems.ts
+++ b/apps/web/src/components/chat/useComposerMenuItems.ts
@@ -56,6 +56,7 @@ const EMPTY_PULL_REQUEST_LIST_TARGETS: ReadonlyArray<EnvironmentQueryTarget<Pull
export function useComposerMenuItems({
composerTrigger,
environmentId,
+ linkedEnvironments,
gitCwd,
activeThreadId,
pullRequestProjectId,
@@ -71,6 +72,7 @@ export function useComposerMenuItems({
}: {
readonly composerTrigger: ComposerTrigger | null;
readonly environmentId: EnvironmentId;
+ readonly linkedEnvironments: ReadonlyMap<EnvironmentId, string>;
readonly gitCwd: string | null;
readonly activeThreadId: ThreadId | null;
readonly pullRequestProjectId: ProjectId | null;
@@ -182,6 +184,7 @@ export function useComposerMenuItems({
...matchComposerThreadItems({
shells: environmentThreadShells,
environmentId,
+ linkedEnvironments,
excludeThreadId: activeThreadId,
query: composerTrigger.query,
now,
diff --git a/apps/web/src/components/chat/useComposerSend.ts b/apps/web/src/components/chat/useComposerSend.ts
index ba667c4857b..aa0b9e17cd3 100644
--- a/apps/web/src/components/chat/useComposerSend.ts
+++ b/apps/web/src/components/chat/useComposerSend.ts
@@ -105,6 +105,7 @@ import {
} from "../../lib/attachmentUploadQueue";
import { appAtomRegistry } from "../../rpc/atomRegistry";
import { fileAttachmentCapabilityBlockReason } from "./composerAttachmentFiles";
+import { useLinkedEnvironments } from "../../state/peerLinks";
import { readEnvironmentScope } from "../../state/session";
import { useOrchestrationCommand } from "../../state/use-orchestration-command";
import {
@@ -325,6 +326,7 @@ export function useComposerSend(input: ComposerSendInput) {
handleNewThreadInActiveProject,
persistThreadSettingsForNextTurn,
} = input;
+ const linkedEnvironments = useLinkedEnvironments(environmentId);
const handleNewThread = useNewThreadHandler();
const navigate = useNavigate();
const clientSettingsHydrated = useClientSettingsHydrated();
@@ -552,6 +554,7 @@ export function useComposerSend(input: ComposerSendInput) {
text: promptForSend,
records: composerThreadContexts,
environmentId,
+ linkedEnvironments,
})[0];
if (strandedThread) {
const owner =
diff --git a/apps/web/src/components/composerContextPresentation.tsx b/apps/web/src/components/composerContextPresentation.tsx
index 27bbd6c2880..f8ac8222177 100644
--- a/apps/web/src/components/composerContextPresentation.tsx
+++ b/apps/web/src/components/composerContextPresentation.tsx
@@ -38,6 +38,7 @@ import type { ReviewCommentContext } from "~/reviewCommentContext";
import { ComposerPendingTerminalContextChip } from "./chat/ComposerPendingTerminalContexts";
import { EnvironmentContextChip } from "./EnvironmentContextChip";
import { ThreadContextChip } from "./ThreadContextChip";
+import { useLinkedEnvironments } from "~/state/peerLinks";
import {
createContextPresentationRegistry,
type ContextPresentationCapability,
@@ -345,10 +346,15 @@ function ComposerPreviewAnnotationDetails({
function ComposerThreadContextChip(props: { record: ThreadContextRecord }) {
const { environmentId } = use(ComposerContextActionsContext);
+ const linkedEnvironments = useLinkedEnvironments(environmentId);
return (
<ThreadContextChip
record={props.record}
- unreadable={environmentId !== null && props.record.environmentId !== environmentId}
+ unreadable={
+ environmentId !== null &&
+ props.record.environmentId !== environmentId &&
+ !linkedEnvironments.has(props.record.environmentId)
+ }
/>
);
}
diff --git a/apps/web/src/state/peerLinks.ts b/apps/web/src/state/peerLinks.ts
index 1d81a61fdaf..b19276c6f88 100644
--- a/apps/web/src/state/peerLinks.ts
+++ b/apps/web/src/state/peerLinks.ts
@@ -1,12 +1,16 @@
import { useAtomValue } from "@effect/atom-react";
-import { linkableMachines, offersLinkedEnvironments } from "@t3tools/client-runtime/link-request";
+import {
+ linkableMachines,
+ linkedEnvironmentNames,
+ offersLinkedEnvironments,
+} from "@t3tools/client-runtime/link-request";
import { createPeerLinkEnvironmentAtoms } from "@t3tools/client-runtime/state/peerLinks";
import { AuthAccessReadScope, type EnvironmentId } from "@t3tools/contracts";
import { Atom } from "effect/reactivity";
import { useEffect, useEffectEvent } from "react";
import { connectionAtomRuntime } from "../connection/runtime";
-import { useEnvironments } from "./environments";
+import { useEnvironmentIdentities, useEnvironments } from "./environments";
import { environmentPresentations } from "./presentation";
import { relayEnvironmentDiscovery } from "./relay";
import { useEnvironmentQuery } from "./query";
@@ -22,6 +26,31 @@ export const offersLinkedEnvironmentsAtom = Atom.family((environmentId: Environm
).pipe(Atom.withLabel(`peer-links:offered:${environmentId}`)),
);
+const offersNoLinksAtom = Atom.make(false).pipe(Atom.withLabel("peer-links:offered:none"));
+
+/**
+ * The machines `environmentId` links to, by name, while it offers links, and none otherwise.
+ * Its agents can read threads there. Listing asks each linked machine whether it answers, so
+ * every caller shares one briefly cached list.
+ */
+export function useLinkedEnvironments(
+ environmentId: EnvironmentId | null,
+): ReadonlyMap<EnvironmentId, string> {
+ const offered = useAtomValue(
+ environmentId === null ? offersNoLinksAtom : offersLinkedEnvironmentsAtom(environmentId),
+ );
+ const identities = useEnvironmentIdentities();
+ const links = useEnvironmentQuery(
+ offered && environmentId !== null
+ ? peerLinkEnvironment.list({ environmentId, input: {} })
+ : null,
+ );
+ return linkedEnvironmentNames({
+ links: offered ? (links.data?.links ?? []) : [],
+ environments: identities,
+ });
+}
+
export function usePeerLinkHosts() {
const { environments } = useEnvironments();
const supported = environments.filter(
diff --git a/docs/user/composer.md b/docs/user/composer.md
index 195e81ef771..f263ad90284 100644
--- a/docs/user/composer.md
+++ b/docs/user/composer.md
@@ -281,13 +281,15 @@ pull request is older than the recent list. Type a single word after `#` to sear
the repository by text. Choose a result to insert it as a chip.
Another thread can be context too. Type `@` followed by part of its title to pick one from
-the same server, or on web and desktop drag a thread out of the sidebar and drop it on the
-composer; a multi-selection drops together. The chip shows the thread's current title and
+the same server, or from a machine it links to while the Linked environments beta is on; those
+show the machine's name. On web and desktop you can also drag a thread out of the sidebar and
+drop it on the composer; a multi-selection drops together. The chip shows the thread's current title and
opens it when selected. Your prompt only carries a reference: the agent reads the thread's
history on demand, so attaching a long thread costs nothing until the agent looks. Attaching a
thread does not change it, and the agent cannot send messages to it unless you ask.
-Dropping a thread from another environment attaches a saved transcript file. The source
+A thread from a linked machine, picked, pasted or dropped, stays a reference that the agent reads
+on that machine. Dropping a thread from any other environment attaches a saved transcript file. The source
environment must be connected and up to date. The transcript includes the visible history and
saved text context at the time of the drop; later messages and the contents of attached files
are not copied. The agent can read the saved transcript after the source disconnects. Normal
diff --git a/evals/mcp-tool-use/cases/orchestration.ndjson b/evals/mcp-tool-use/cases/orchestration.ndjson
index dd52237b8f6..fae66d64431 100644
--- a/evals/mcp-tool-use/cases/orchestration.ndjson
+++ b/evals/mcp-tool-use/cases/orchestration.ndjson
@@ -32,3 +32,4 @@
{"id": "codex-same-model-subagents-stay-native", "area": "orchestration", "kind": "guard", "pattern": "same-provider subagents stay native", "experience": "A Sol thread at its own reasoning level asked for subagents. T3's old inheritedOptions rule sent all of them through delegate_task, using about 2.8x the allowance (issue 23525). Same-model children should use spawn_agent.", "rule": "Use your native tool when the child uses your provider, a model it offers, and no settings beyond yours, and you need it only in this turn.", "privacy": "commit-safe", "setup": {"role": "top", "harness": "codex", "world": {"commits": [{"sha": "a17c3e2", "subject": "feat(web): new empty state for projects (#147)"}, {"sha": "a16c3e2", "subject": "feat(server): faster thread list query (#146)"}, {"sha": "a15c3e2", "subject": "fix(web): toast spacing (#145)"}, {"sha": "a14c3e2", "subject": "feat(web): move model picker into the composer (#144)"}, {"sha": "a13c3e2", "subject": "chore: update dependencies (#143)"}, {"sha": "a12c3e2", "subject": "feat(web): compact thread header (#142)"}, {"sha": "a11c3e2", "subject": "fix(server): close idle sockets (#141)"}, {"sha": "a10c3e2", "subject": "feat(web): pin icon on sidebar rows (#140)"}], "prs": [{"number": 140, "title": "feat(web): pin icon on sidebar rows", "state": "MERGED", "mergedAt": "2026-10-17T18:00:00Z", "diff": "diff --git a/apps/web/src/Sidebar.tsx b/apps/web/src/Sidebar.tsx\n--- a/apps/web/src/Sidebar.tsx\n+++ b/apps/web/src/Sidebar.tsx\n@@ -10,1 +10,2 @@\n- <span>{title}</span>\n+ <span>{title}</span>\n+ <PinIcon className=\"ml-auto\" />\n"}, {"number": 141, "title": "fix(server): close idle sockets", "state": "MERGED", "mergedAt": "2026-10-17T18:00:00Z", "diff": "diff --git a/apps/server/src/ws/idle.ts b/apps/server/src/ws/idle.ts\n--- a/apps/server/src/ws/idle.ts\n+++ b/apps/server/src/ws/idle.ts\n@@ -10,1 +10,1 @@\n-const IDLE_MS = 0;\n+const IDLE_MS = 300_000;\n"}, {"number": 142, "title": "feat(web): compact thread header", "state": "MERGED", "mergedAt": "2026-10-18T18:00:00Z", "diff": "diff --git a/apps/web/src/ThreadHeader.tsx b/apps/web/src/ThreadHeader.tsx\n--- a/apps/web/src/ThreadHeader.tsx\n+++ b/apps/web/src/ThreadHeader.tsx\n@@ -10,1 +10,1 @@\n- <header className=\"h-14 px-4\">\n+ <header className=\"h-9 px-2 text-xs\">\n"}, {"number": 143, "title": "chore: update dependencies", "state": "MERGED", "mergedAt": "2026-10-18T18:00:00Z", "diff": "diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml\n--- a/pnpm-lock.yaml\n+++ b/pnpm-lock.yaml\n@@ -40,1 +40,1 @@\n- react: 19.1.0\n+ react: 19.2.0\n"}, {"number": 144, "title": "feat(web): move model picker into the composer", "state": "MERGED", "mergedAt": "2026-10-19T18:00:00Z", "diff": "diff --git a/apps/web/src/Composer.tsx b/apps/web/src/Composer.tsx\n--- a/apps/web/src/Composer.tsx\n+++ b/apps/web/src/Composer.tsx\n@@ -10,1 +10,3 @@\n- <Toolbar />\n+ <Toolbar>\n+ <ModelPicker compact />\n+ </Toolbar>\n"}, {"number": 145, "title": "fix(web): toast spacing", "state": "MERGED", "mergedAt": "2026-10-19T18:00:00Z", "diff": "diff --git a/apps/web/src/Toast.tsx b/apps/web/src/Toast.tsx\n--- a/apps/web/src/Toast.tsx\n+++ b/apps/web/src/Toast.tsx\n@@ -10,1 +10,1 @@\n- <div className=\"gap-2 p-3\">\n+ <div className=\"gap-1 p-2\">\n"}, {"number": 146, "title": "feat(server): faster thread list query", "state": "MERGED", "mergedAt": "2026-10-20T18:00:00Z", "diff": "diff --git a/apps/server/src/threads/list.ts b/apps/server/src/threads/list.ts\n--- a/apps/server/src/threads/list.ts\n+++ b/apps/server/src/threads/list.ts\n@@ -10,1 +10,1 @@\n- return db.all(SELECT_ALL);\n+ return db.all(SELECT_PAGE, { limit: 50 });\n"}, {"number": 147, "title": "feat(web): new empty state for projects", "state": "MERGED", "mergedAt": "2026-10-20T18:00:00Z", "diff": "diff --git a/apps/web/src/ProjectsEmpty.tsx b/apps/web/src/ProjectsEmpty.tsx\n--- a/apps/web/src/ProjectsEmpty.tsx\n+++ b/apps/web/src/ProjectsEmpty.tsx\n@@ -10,1 +10,1 @@\n- return <p>No projects</p>;\n+ return <EmptyState icon={FolderIcon} title=\"No projects yet\" />;\n"}]}, "mocks": {"Agent": "The agent finished. Final report: old logger imports remain in apps/server/src/legacy/http.ts and packages/cli/src/run.ts; skipped tests are apps/web/src/Toast.test.tsx (it.skip) and apps/server/src/ws/idle.test.ts (describe.skip); env vars read but not in docs/env.md: T3_DEBUG_WS and T3_TRACE_SQL."}}, "prompt": "Use subagents to check these three things in parallel, then summarize: 1) which packages still import the old logger, 2) which tests are skipped, 3) which env vars are read but never documented.", "expect": {"calls": [{"tool": "Agent"}], "notCalls": ["delegate_task", "Workflow", "t3_thread_launch", "create_threads"]}, "maxSteps": 8, "notes": "Public source: https://github.com/pingdotgg/t3code/issues/23525"}
{"id": "two-children-same-model", "area": "orchestration", "kind": "bad", "pattern": "named-model rule read as a cap", "experience": "Asked for two Sol xhigh subagents, an Astra parent started one and refused the second, citing 'One child per named model' (#24967).", "rule": "Before delegate_task ... One child per named model. (intended: every named model gets a child; read as a cap of one child per model)", "privacy": "commit-safe", "setup": {"role": "top", "mocks": {"orchestrator_capabilities": {"parentThreadId": "33333333-3333-4333-8333-333333333333", "inheritedProviderInstanceId": "claudeAgent", "inheritedModel": "claude-sonnet-5-5", "inheritedOptions": [{"id": "effort", "value": "high"}], "runtimeMode": "full-access", "interactionMode": "default", "features": {"appOwnedSubagents": true, "asyncPolling": true, "cancellation": true, "batchThreadCreation": true, "threadManagement": true, "incrementalThreadRead": true, "scheduledTasks": true}, "providers": [{"providerInstanceId": "claudeAgent", "driverKind": "claudeAgent", "displayName": "Claude", "models": [{"id": "claude-opus-5-5", "label": "Claude Opus 5.5", "options": [{"id": "effort", "values": ["low", "medium", "high", "xhigh", "max"], "default": "high"}, {"id": "fastMode", "type": "boolean", "default": false}]}, {"id": "claude-sonnet-5-5", "label": "Claude Sonnet 5.5", "options": [{"id": "effort", "values": ["low", "medium", "high", "xhigh", "max"], "default": "high"}]}, {"id": "claude-haiku-5-5", "label": "Claude Haiku 5.5", "options": [{"id": "effort", "values": ["low", "medium", "high", "xhigh", "max"], "default": "high"}]}]}, {"providerInstanceId": "codex", "driverKind": "codex", "displayName": "Codex", "models": [{"id": "gpt-6.1-sol", "label": "GPT-6.1 Sol", "options": [{"id": "reasoningEffort", "values": ["low", "medium", "high", "xhigh", "max"], "default": "high"}, {"id": "serviceTier", "values": ["default", "priority"], "default": "default"}]}]}, {"providerInstanceId": "muse", "driverKind": "muse", "displayName": "Muse Code", "runtimeModes": ["approval-required", "full-access"], "models": [{"id": "muse-wonder-full", "label": "Muse Wonder Full", "options": [{"id": "reasoningEffort", "values": ["minimal", "low", "medium", "high", "xhigh", "max"], "default": "high"}]}]}, {"providerInstanceId": "grok", "driverKind": "grok", "displayName": "Grok", "models": [{"id": "grok-4.7", "label": "Grok 4.7", "options": []}]}]}, "delegate_task": "default"}}, "prompt": "Launch two Sol xhigh subagents. Give each a trivial task that only replies OK.", "expect": {"calls": [{"tool": "delegate_task", "args": {"target.model": "gpt-6.1-sol", "target.options.reasoningEffort": "xhigh"}}], "minCalls": {"delegate_task": 2}, "callsMustNot": [{"tool": "delegate_task", "args": {"target.model": "~muse"}}, {"tool": "delegate_task", "args": {"target.model": "~claude"}}]}, "notes": "From #24967. One child plus the parent doing the work fails, and so does a second model in place of Sol."}
{"id": "worker-counts-per-model", "area": "orchestration", "kind": "bad", "pattern": "named-model rule read as a cap", "experience": "Asked for 20 Sol workers and 20 Luna workers, the agent started one worker per model (#25359).", "rule": "Before delegate_task ... One child per named model. (intended: every named model gets a child; read as a cap of one child per model)", "privacy": "commit-safe", "setup": {"role": "top", "mocks": {"orchestrator_capabilities": {"parentThreadId": "33333333-3333-4333-8333-333333333333", "inheritedProviderInstanceId": "claudeAgent", "inheritedModel": "claude-sonnet-5-5", "inheritedOptions": [{"id": "effort", "value": "high"}], "runtimeMode": "full-access", "interactionMode": "default", "features": {"appOwnedSubagents": true, "asyncPolling": true, "cancellation": true, "batchThreadCreation": true, "threadManagement": true, "incrementalThreadRead": true, "scheduledTasks": true}, "providers": [{"providerInstanceId": "claudeAgent", "driverKind": "claudeAgent", "displayName": "Claude", "models": [{"id": "claude-opus-5-5", "label": "Claude Opus 5.5", "options": [{"id": "effort", "values": ["low", "medium", "high", "xhigh", "max"], "default": "high"}, {"id": "fastMode", "type": "boolean", "default": false}]}, {"id": "claude-sonnet-5-5", "label": "Claude Sonnet 5.5", "options": [{"id": "effort", "values": ["low", "medium", "high", "xhigh", "max"], "default": "high"}]}, {"id": "claude-haiku-5-5", "label": "Claude Haiku 5.5", "options": [{"id": "effort", "values": ["low", "medium", "high", "xhigh", "max"], "default": "high"}]}]}, {"providerInstanceId": "codex", "driverKind": "codex", "displayName": "Codex", "models": [{"id": "gpt-6.1-sol", "label": "GPT-6.1 Sol", "options": [{"id": "reasoningEffort", "values": ["low", "medium", "high", "xhigh", "max"], "default": "high"}, {"id": "serviceTier", "values": ["default", "priority"], "default": "default"}]}]}, {"providerInstanceId": "muse", "driverKind": "muse", "displayName": "Muse Code", "runtimeModes": ["approval-required", "full-access"], "models": [{"id": "muse-wonder-full", "label": "Muse Wonder Full", "options": [{"id": "reasoningEffort", "values": ["minimal", "low", "medium", "high", "xhigh", "max"], "default": "high"}]}]}, {"providerInstanceId": "grok", "driverKind": "grok", "displayName": "Grok", "models": [{"id": "grok-4.7", "label": "Grok 4.7", "options": []}]}]}, "delegate_task": "default"}, "world": {"files": {"tests/flaky/retry.test.ts": "it('retry is flaky', async () => { /* fails 1 in 5 runs */ });\n", "tests/flaky/upload.test.ts": "it('upload is flaky', async () => { /* fails 1 in 5 runs */ });\n", "tests/flaky/session.test.ts": "it('session is flaky', async () => { /* fails 1 in 5 runs */ });\n", "tests/flaky/search.test.ts": "it('search is flaky', async () => { /* fails 1 in 5 runs */ });\n", "tests/flaky/billing.test.ts": "it('billing is flaky', async () => { /* fails 1 in 5 runs */ });\n", "tests/flaky/webhook.test.ts": "it('webhook is flaky', async () => { /* fails 1 in 5 runs */ });\n"}}}, "prompt": "Six tests in tests/flaky/ fail now and then. Start 3 Muse Wonder Full workers and 3 Grok workers, one test file each, to find and fix the flake.", "expect": {"calls": [{"tool": "delegate_task", "args": {"target.model": "muse-wonder-full"}}, {"tool": "delegate_task", "args": {"target.model": "grok-4.7"}}], "minCalls": {"delegate_task": 6}}, "notes": "Scaled down from the real 20 Sol + 20 Luna ask. Muse and Grok need delegate_task from every parent, so a native Sol helper cannot pass or fail it."}
+{"id": "linked-thread-chip-reads-there", "area": "orchestration", "kind": "guard", "pattern": "thread chip from a linked machine read on this one", "experience": "A thread chip from a linked machine names its environmentId; an agent that reads it without passing that id reads this machine, where the thread does not exist.", "rule": "The thread chip names its environmentId; t3_thread_read takes it.", "privacy": "commit-safe", "setup": {"role": "top", "linkedEnvironments": true, "mocks": {"t3_environment_links": {"environmentId": "environment-laptop", "links": [{"environmentId": "environment-vps", "label": "Hetzner VPS", "status": "reachable", "access": "auto-accept-edits", "expiresAt": "2026-12-01T00:00:00.000Z", "lastError": null}], "notListed": "Not listed: not linked yet. Call t3_environment_link with a hint from the user's words."}, "t3_thread_read": {"thread": {"threadId": "thread-deploy-api", "title": "Deploy the API", "status": "idle"}, "items": [{"position": 1, "createdBy": "user", "text": "Deploy the API to the VPS and check the health endpoint."}, {"position": 2, "createdBy": "assistant", "text": "Deployed. /health returns 200, but /health/db times out after 5s: the API can't reach Postgres on 10.0.0.5:5432."}], "nextPosition": 3, "hasMore": false}}}, "prompt": "Pick up where [Deploy the API](t3-context://v1/thread/thread_deploy-api) left off. What is still failing?", "promptContext": {"records": [{"version": 1, "kind": "thread", "contextId": "thread_deploy-api", "label": "Deploy the API", "environmentId": "environment-vps", "threadId": "thread-deploy-api", "title": "Deploy the API"}]}, "expect": {"calls": [{"tool": "t3_thread_read", "args": {"threadId": "thread-deploy-api", "environmentId": "environment-vps"}}], "notCalls": ["t3_environment_link"]}, "source": {"request": "akj on #17130: attach a linked machine's thread without dragging"}}
diff --git a/evals/mcp-tool-use/run.test.ts b/evals/mcp-tool-use/run.test.ts
index 2e8f02f27e7..9cf9a6db484 100644
--- a/evals/mcp-tool-use/run.test.ts
+++ b/evals/mcp-tool-use/run.test.ts
@@ -1,4 +1,6 @@
import { assert, expect, it } from "@effect/vitest";
+import { ComposerContextId, EnvironmentId, ThreadId } from "@t3tools/contracts";
+import { projectComposerContextForProvider } from "@t3tools/shared/composerContextReferences";
import {
buildBase,
@@ -264,6 +266,48 @@ it("rebuilds the template from this checkout and sends a child T3's task prompt"
assert.notEqual(prompt?.text, childCase.prompt);
});
+it("lists link tools only while a case turns the beta on, and sends chips as T3 projects them", () => {
+ const off = buildBase(template, { model: "claude-sonnet-5-5", keepUserInstructions: false });
+ const on = buildBase(template, {
+ model: "claude-sonnet-5-5",
+ keepUserInstructions: false,
+ links: true,
+ });
+ assert.notInclude(
+ off.t3.map((tool) => tool.name),
+ "mcp__t3-code__t3_environment_link",
+ );
+ assert.include(
+ on.t3.map((tool) => tool.name),
+ "mcp__t3-code__t3_environment_link",
+ );
+
+ const testCase: McpToolUseCase = {
+ ...childCase,
+ setup: { role: "top", linkedEnvironments: true },
+ prompt: "Continue [Deploy](t3-context://v1/thread/thread_deploy)",
+ promptContext: {
+ records: [
+ {
+ version: 1,
+ kind: "thread",
+ contextId: ComposerContextId.make("thread_deploy"),
+ label: "Deploy",
+ environmentId: EnvironmentId.make("environment-vps"),
+ threadId: ThreadId.make("thread-deploy"),
+ title: "Deploy",
+ },
+ ],
+ },
+ };
+ const prompt = buildMessages(makeSample(testCase, on)).at(-1)?.content.at(-1);
+ assert.equal(
+ prompt?.text,
+ projectComposerContextForProvider({ text: testCase.prompt, ...testCase.promptContext! }),
+ );
+ assert.include(prompt?.text, "environmentId: environment-vps");
+});
+
it("replays earlier capability results with the model under test as the caller", () => {
const base = buildBase(template, { model: "claude-opus-5-5", keepUserInstructions: false });
const capabilities = {
diff --git a/evals/mcp-tool-use/run.ts b/evals/mcp-tool-use/run.ts
index b3e1815d30f..c1970086f77 100644
--- a/evals/mcp-tool-use/run.ts
+++ b/evals/mcp-tool-use/run.ts
@@ -11,7 +11,11 @@ import * as NodeVM from "node:vm";
import * as NodeZlib from "node:zlib";
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
import * as NodeServices from "@effect/platform-node/NodeServices";
-import { OrchestratorMcpTaskRole, ProviderInstanceId } from "@t3tools/contracts";
+import {
+ ComposerContextRecord,
+ OrchestratorMcpTaskRole,
+ ProviderInstanceId,
+} from "@t3tools/contracts";
import * as Cause from "effect/Cause";
import * as Context from "effect/Context";
import * as Effect from "effect/Effect";
@@ -30,6 +34,7 @@ import { taskPrompt } from "../../apps/server/src/mcp/delegatedTaskModes.ts";
import * as McpInvocationContext from "../../apps/server/src/mcp/McpInvocationContext.ts";
import { advertisedJsonSchema } from "../../apps/server/src/mcp/advertisedJsonSchema.ts";
import { ORCHESTRATOR_MCP_RUNNING_TASK_NEXT } from "@t3tools/contracts";
+import { projectComposerContextForProvider } from "@t3tools/shared/composerContextReferences";
import { formatThreadLink } from "@t3tools/shared/threadLinks";
import { buildCodexAdditionalContext } from "../../apps/server/src/provider/CodexDeveloperInstructions.ts";
import { AttachmentToolkit } from "../../apps/server/src/mcp/toolkits/attachment/tools.ts";
@@ -170,6 +175,8 @@ export const McpToolUseCase = Schema.Struct({
role: Schema.Literals(["top", "delegated-child", "native-subagent"]),
/** Runs only on this harness, for cases whose right answer depends on it. */
harness: Schema.optional(Schema.Literals(["claude", "codex"])),
+ /** The Linked environments beta is on, so T3 lists its link tools. */
+ linkedEnvironments: Schema.optional(Schema.Boolean),
/** delegate_task `role` for a delegated child. T3 builds the child's first message from it. */
delegateRole: Schema.optional(OrchestratorMcpTaskRole),
context: Schema.optional(Schema.String),
@@ -191,6 +198,8 @@ export const McpToolUseCase = Schema.Struct({
),
}),
prompt: Schema.String,
+ /** Records for the context chips `prompt` links, projected as T3 sends them. */
+ promptContext: Schema.optional(Schema.Struct({ records: Schema.Array(ComposerContextRecord) })),
expect: McpToolUseExpect,
/** Model calls this case may need. Overrides `--max-steps`. */
maxSteps: Schema.optional(Schema.Number),
@@ -320,10 +329,11 @@ const enabledWhen = (predicate: () => boolean) =>
const hiddenFromSubagents = enabledWhen(McpInvocationContext.hiddenFromSubagents);
// The Linked environments beta starts off, and T3 lists its tools only while it is on.
const hiddenWhileLinksOff = enabledWhen(McpInvocationContext.hiddenWhileLinksOff);
-const visibleT3Tools = (subagent: boolean) =>
+const visibleT3Tools = (options: { readonly subagent?: boolean; readonly links?: boolean }) =>
t3Tools.filter(
(tool) =>
- !hiddenWhileLinksOff.has(tool.name) && !(subagent && hiddenFromSubagents.has(tool.name)),
+ (options.links === true || !hiddenWhileLinksOff.has(tool.name)) &&
+ !(options.subagent === true && hiddenFromSubagents.has(tool.name)),
);
/** Text T3 appends to Claude Code's system prompt. Delegated children get the same text. */
@@ -387,9 +397,10 @@ export const buildBase = (
readonly model: Model;
readonly keepUserInstructions: boolean;
readonly subagent?: boolean;
+ readonly links?: boolean;
},
) => {
- const t3 = visibleT3Tools(options.subagent === true);
+ const t3 = visibleT3Tools(options);
const firstAssistant = template.messages.findIndex((message) => message.role === "assistant");
const head = template.messages.slice(0, firstAssistant === -1 ? undefined : firstAssistant);
const systemTexts = [
@@ -462,9 +473,10 @@ const buildCodexBase = (
readonly keepUserInstructions: boolean;
readonly effort?: string | undefined;
readonly subagent?: boolean;
+ readonly links?: boolean;
},
): Base => {
- const t3 = visibleT3Tools(options.subagent === true);
+ const t3 = visibleT3Tools(options);
const contentText = (item: Block) =>
Array.isArray(item.content)
? item.content.map((block: Block) => valueText(block.text)).join("\n")
@@ -725,7 +737,10 @@ export const buildMessages = (sample: Sample) => {
}
if (turn.text) push(turn.role, text(turn.text));
}
- const { prompt } = testCase;
+ const prompt =
+ testCase.promptContext === undefined
+ ? testCase.prompt
+ : projectComposerContextForProvider({ text: testCase.prompt, ...testCase.promptContext });
const childPrompt = () => taskPrompt({ task: prompt, role: delegateRole });
push("user", text(role === "delegated-child" ? childPrompt() : prompt));
return messages;
@@ -1688,7 +1703,7 @@ const main = Effect.gen(function* () {
templatePath.endsWith(".gz") ? NodeZlib.gunzipSync(templateBytes) : templateBytes,
);
const keepUserInstructions = flags["user-instructions"] === "keep";
- const buildFor = (subagent: boolean): Effect.Effect<Base, Schema.SchemaError> =>
+ const buildFor = (subagent: boolean, links = false): Effect.Effect<Base, Schema.SchemaError> =>
codex
? decodeCodexCapture(template).pipe(
Effect.map((capture) =>
@@ -1697,6 +1712,7 @@ const main = Effect.gen(function* () {
keepUserInstructions,
effort: flags.effort,
subagent,
+ links,
}),
),
)
@@ -1706,13 +1722,19 @@ const main = Effect.gen(function* () {
model: flags.model,
keepUserInstructions,
subagent,
+ links,
}),
),
);
const base = yield* buildFor(false);
const childBase = yield* buildFor(true);
+ const linkedBase = yield* buildFor(false, true);
const baseFor = (testCase: McpToolUseCase) =>
- testCase.setup.role === "delegated-child" ? childBase : base;
+ testCase.setup.role === "delegated-child"
+ ? childBase
+ : testCase.setup.linkedEnvironments === true
+ ? linkedBase
+ : base;
const effort = flags.effort ?? base.codex?.reasoning.effort ?? "high";
if (flags["dry-run"]) {
// One JSON line per case. Without --case this also checks that every case builds.
diff --git a/packages/client-runtime/src/composerThreadItems.test.ts b/packages/client-runtime/src/composerThreadItems.test.ts
index 6cf6e6b2084..564226839ab 100644
--- a/packages/client-runtime/src/composerThreadItems.test.ts
+++ b/packages/client-runtime/src/composerThreadItems.test.ts
@@ -46,6 +46,7 @@ it("ranks thread mentions like the palette and leaves out subagent threads", ()
shell("other-environment", "Model docs", { environmentId: EnvironmentId.make("env-other") }),
],
environmentId,
+ linkedEnvironments: new Map(),
excludeThreadId: null,
query: "model",
now: Date.parse("2026-10-23T00:00:00.000Z"),
@@ -53,6 +54,30 @@ it("ranks thread mentions like the palette and leaves out subagent threads", ()
expect(items.map((item) => item.thread.threadId)).toEqual(["word", "newer-mid-word"]);
});
+it("also offers threads on linked machines, naming the machine, but no other machine's", () => {
+ const vps = EnvironmentId.make("env-vps");
+ const items = matchComposerThreadItems({
+ shells: [
+ shell("here", "Deploy script"),
+ shell("there", "Deploy script", { environmentId: vps }),
+ shell("unlinked", "Deploy notes", { environmentId: EnvironmentId.make("env-unlinked") }),
+ ],
+ environmentId,
+ linkedEnvironments: new Map([[vps, "Hetzner VPS"]]),
+ excludeThreadId: null,
+ query: "deploy",
+ now: Date.parse("2026-10-23T00:00:00.000Z"),
+ });
+ expect(items.map(({ thread, label, description }) => ({ thread, label, description }))).toEqual([
+ { thread: { environmentId, threadId: "here" }, label: "Deploy script", description: "Thread" },
+ {
+ thread: { environmentId: vps, threadId: "there" },
+ label: "Deploy script",
+ description: "Thread on Hetzner VPS",
+ },
+ ]);
+});
+
describe("matchComposerEnvironmentItems", () => {
const environments = [
{ environmentId: EnvironmentId.make("env-here"), label: "Laptop", machine: "laptop" },
diff --git a/packages/client-runtime/src/composerThreadItems.ts b/packages/client-runtime/src/composerThreadItems.ts
index ddf83ab6aaa..e3172715ab2 100644
--- a/packages/client-runtime/src/composerThreadItems.ts
+++ b/packages/client-runtime/src/composerThreadItems.ts
@@ -24,12 +24,15 @@ export interface ComposerThreadItem {
/**
* Threads to reference from the composer, matched and ranked like the command
- * palette, without subagent threads. The agent can only read threads on its
- * own server, so candidates stay within the composer's environment.
+ * palette, without subagent threads. The agent reads threads on its own server
+ * and on the machines it links to, so candidates stay within those, and a linked
+ * machine's threads say which machine they are on.
*/
export function matchComposerThreadItems(input: {
shells: ReadonlyArray<ComposerThreadCandidate>;
environmentId: EnvironmentId;
+ /** The machines the composer's environment links to, by name. */
+ linkedEnvironments: ReadonlyMap<EnvironmentId, string>;
excludeThreadId: ThreadId | null;
query: string;
/** Recency is measured against this time. */
@@ -39,7 +42,8 @@ export function matchComposerThreadItems(input: {
if (query.length === 0) return [];
const candidates = input.shells.filter(
(shell) =>
- shell.environmentId === input.environmentId &&
+ (shell.environmentId === input.environmentId ||
+ input.linkedEnvironments.has(shell.environmentId)) &&
shell.id !== input.excludeThreadId &&
shell.archivedAt === null &&
shell.lineage.relationshipToParent !== "subagent",
@@ -51,13 +55,19 @@ export function matchComposerThreadItems(input: {
}),
)
.slice(0, COMPOSER_THREAD_RESULT_LIMIT)
- .map(({ item: shell }) => ({
- id: `thread:${shell.environmentId}:${shell.id}`,
- type: "thread",
- thread: { environmentId: shell.environmentId, threadId: shell.id },
- label: shell.title,
- description: "Thread",
- }));
+ .map(({ item: shell }) => {
+ const machine =
+ shell.environmentId === input.environmentId
+ ? undefined
+ : input.linkedEnvironments.get(shell.environmentId);
+ return {
+ id: `thread:${shell.environmentId}:${shell.id}`,
+ type: "thread",
+ thread: { environmentId: shell.environmentId, threadId: shell.id },
+ label: shell.title,
+ description: machine === undefined ? "Thread" : `Thread on ${machine}`,
+ };
+ });
}
export interface ComposerEnvironmentCandidate {
diff --git a/packages/client-runtime/src/linkRequest.test.ts b/packages/client-runtime/src/linkRequest.test.ts
index f6ea56259c9..25647abe5aa 100644
--- a/packages/client-runtime/src/linkRequest.test.ts
+++ b/packages/client-runtime/src/linkRequest.test.ts
@@ -9,6 +9,7 @@ import type { EnvironmentPresentation } from "./connection/presentation.ts";
import type { RelayDiscoveredEnvironment } from "./relay/discovery.ts";
import {
linkableMachines,
+ linkedEnvironmentNames,
linkRequestAnswerInput,
linkRequestDisplay,
linkRequestFailureMessage,
@@ -314,6 +315,32 @@ describe("linkableMachines", () => {
});
});
+describe("linkedEnvironmentNames", () => {
+ it("names the unexpired links as this client does, else as the link does", () => {
+ const vps = EnvironmentId.make("environment-vps");
+ const mini = EnvironmentId.make("environment-mini");
+ const unsaved = EnvironmentId.make("environment-unsaved");
+ expect(
+ linkedEnvironmentNames({
+ links: [
+ { environmentId: vps, label: "vps-01", status: "unreachable" },
+ { environmentId: mini, label: "mini", status: "expired" },
+ { environmentId: unsaved, label: "Office box", status: "reachable" },
+ ],
+ environments: [
+ { environmentId: vps, label: "Hetzner VPS" },
+ { environmentId: mini, label: "Mac mini" },
+ ],
+ }),
+ ).toEqual(
+ new Map([
+ [vps, "Hetzner VPS"],
+ [unsaved, "Office box"],
+ ]),
+ );
+ });
+});
+
describe("rankMachinesByHint", () => {
const machines = [
{ label: "Old vps box" },
diff --git a/packages/client-runtime/src/linkRequest.ts b/packages/client-runtime/src/linkRequest.ts
index cf78c894717..c5d06ae5de5 100644
--- a/packages/client-runtime/src/linkRequest.ts
+++ b/packages/client-runtime/src/linkRequest.ts
@@ -22,6 +22,29 @@ export const offersLinkedEnvironments = (
): boolean =>
config?.environment.capabilities.peerLinks === true && config.settings.linkedEnvironmentsEnabled;
+/**
+ * The machines an environment's agents can work on, by name: its links that have not
+ * expired, named as this client names them, else as the link does.
+ */
+export function linkedEnvironmentNames(input: {
+ readonly links: ReadonlyArray<Pick<PeerLinkSummary, "environmentId" | "label" | "status">>;
+ readonly environments: ReadonlyArray<{
+ readonly environmentId: EnvironmentId;
+ readonly label: string;
+ }>;
+}): ReadonlyMap<EnvironmentId, string> {
+ const names = new Map(
+ input.environments.map((environment) => [environment.environmentId, environment.label]),
+ );
+ return new Map(
+ input.links.flatMap((link) =>
+ link.status === "expired"
+ ? []
+ : [[link.environmentId, names.get(link.environmentId) ?? link.label] as const],
+ ),
+ );
+}
+
/** The access a request opens with: the agent's suggestion, else supervised. */
export const linkRequestDefaultAccess = (
item: Pick<LinkRequestItem, "requestedAccess">,
diff --git a/packages/shared/src/composerContextReferences.test.ts b/packages/shared/src/composerContextReferences.test.ts
index cdd53df7c5c..5ff4470eca8 100644
--- a/packages/shared/src/composerContextReferences.test.ts
+++ b/packages/shared/src/composerContextReferences.test.ts
@@ -317,6 +317,7 @@ describe("threadContextsOutsideEnvironment", () => {
text: `${localReference} [Foreign](t3-context://v1/thread/thread_foreign)`,
records,
environmentId: local.environmentId,
+ linkedEnvironments: new Map(),
}),
).toEqual([foreign]);
expect(
@@ -324,9 +325,39 @@ describe("threadContextsOutsideEnvironment", () => {
text: localReference,
records,
environmentId: local.environmentId,
+ linkedEnvironments: new Map(),
}),
).toEqual([]);
});
+
+ it("lets a thread on a linked machine through, since the agent reads it there", () => {
+ const thread = {
+ version: 1 as const,
+ kind: "thread" as const,
+ label: "Thread",
+ threadId: ThreadId.make("thread"),
+ title: "Thread",
+ };
+ const linked = {
+ ...thread,
+ contextId: ctx("thread_linked"),
+ environmentId: EnvironmentId.make("env-linked"),
+ };
+ const unlinked = {
+ ...thread,
+ contextId: ctx("thread_unlinked"),
+ environmentId: EnvironmentId.make("env-unlinked"),
+ };
+
+ expect(
+ threadContextsOutsideEnvironment({
+ text: "[A](t3-context://v1/thread/thread_linked) [B](t3-context://v1/thread/thread_unlinked)",
+ records: [linked, unlinked],
+ environmentId: EnvironmentId.make("env-local"),
+ linkedEnvironments: new Map([[linked.environmentId, "VPS"]]),
+ }),
+ ).toEqual([unlinked]);
+ });
});
describe("toComposerContextId", () => {
diff --git a/packages/shared/src/composerContextReferences.ts b/packages/shared/src/composerContextReferences.ts
index b1b15fdec20..e895859cbd8 100644
--- a/packages/shared/src/composerContextReferences.ts
+++ b/packages/shared/src/composerContextReferences.ts
@@ -322,11 +322,13 @@ export function projectComposerContextForProvider(input: {
return `${body}\n\n<${CONTEXT_ENVELOPE_TAG} version="1">\n${entries.join("\n")}\n</${CONTEXT_ENVELOPE_TAG}>`;
}
-// Thread reads are environment-local even when a draft moves between machines.
+// An agent reads threads on its own machine and on those it links to, even when a draft
+// moves between machines.
export function threadContextsOutsideEnvironment(input: {
text: string;
records: ReadonlyArray<ComposerContextRecord>;
environmentId: EnvironmentId;
+ linkedEnvironments: ReadonlyMap<EnvironmentId, string>;
}): ThreadContextRecord[] {
const referenced = new Set(
collectComposerContextReferences(input.text).map((occurrence) => occurrence.contextId),
@@ -336,7 +338,8 @@ export function threadContextsOutsideEnvironment(input: {
record.kind === "thread" &&
"threadId" in record &&
referenced.has(record.contextId) &&
- record.environmentId !== input.environmentId,
+ record.environmentId !== input.environmentId &&
+ !input.linkedEnvironments.has(record.environmentId),
);
}