The best way to control Claude Code, Codex and more from any computer or phone
fix(peer): link requests use the addresses the app already has for a machine (#34139)
Co-authored-by: Claude Mythos 5.2 <noreply@anthropic.com>
Theo Browne committed
Nov 10, 2026 at 19:00 UTC
92f1b8ec253456c00416fc1d45cb3deb5cf8e264
16 files changed
+401
-174
apps/mobile/src/features/threads/LinkRequestCard.tsx
+31
-50
@@ -1,13 +1,16 @@
1
import { pipe } from "effect/Function";
2
import { useAtomValue } from "@effect/atom-react";
3
import {
4
+ ANOTHER_ADDRESS,
5
type LinkableMachine,
6
+ linkDestination,
7
linkRequestAnswerInput,
8
linkRequestDefaultAccess,
9
linkRequestDisplay,
10
linkRequestFailureMessage,
11
linkRequestInitialMachine,
12
type LinkRequestItem,
13
+ linkRequestTarget,
14
linkRequestTargetName,
15
rankMachinesByHint,
16
} from "@t3tools/client-runtime/link-request";
@@ -58,9 +61,6 @@ const accessLabel = (access: AuthMcpClientAccess) =>
61
62
const LINK_SYMBOL: AppSymbolName = { ios: "link", android: "desktop_windows" };
63
61
-/** The machine list's row for linking by an address typed in. */
62
-const ANOTHER_ADDRESS = "another-address";
63
-
64
/** Whether the agent left the machine for the user to pick. */
65
const picksMachine = (item: LinkRequestItem) =>
66
item.environmentId === undefined && item.url === undefined;
@@ -141,11 +141,6 @@ function PendingLinkRequest(props: {
141
{item.reason.trim() ? (
142
<Text className="font-sans text-sm leading-5 text-foreground-muted">{item.reason}</Text>
143
) : null}
144
- {item.label !== undefined && item.url !== undefined ? (
145
- <Text className="font-sans text-xs text-foreground-muted" numberOfLines={1}>
146
- {item.url}
147
- </Text>
148
- ) : null}
144
</View>
145
{error !== null ? (
146
<Text
@@ -194,37 +189,6 @@ function PendingLinkRequest(props: {
189
);
190
}
191
197
-/** What the sheet links; see web's LinkRequestDialog for the same rules. */
198
-type SheetTarget =
199
- | { readonly kind: "none" }
200
- | {
201
- readonly kind: "machine";
202
- readonly environmentId: EnvironmentId;
203
- readonly label: string;
204
- readonly urls: ReadonlyArray<string>;
205
- readonly linked: boolean;
206
- }
207
- | { readonly kind: "address" };
208
-
209
-function resolveTarget(
210
- item: LinkRequestItem,
211
- machines: ReadonlyArray<LinkableMachine>,
212
- choice: string | null,
213
-): SheetTarget {
214
- if (item.environmentId === undefined && item.url !== undefined) return { kind: "address" };
215
- const chosen = item.environmentId ?? choice;
216
- if (chosen === null) return { kind: "none" };
217
- if (chosen === ANOTHER_ADDRESS) return { kind: "address" };
218
- const machine = machines.find((candidate) => candidate.environmentId === chosen);
219
- return {
220
- kind: "machine",
221
- environmentId: machine?.environmentId ?? (chosen as EnvironmentId),
222
- label: machine?.label ?? linkRequestTargetName(item),
223
- urls: [...new Set([...(machine?.urls ?? []), ...(item.url === undefined ? [] : [item.url])])],
224
- linked: machine?.linked ?? false,
225
- };
226
-}
227
-
192
function LinkRequestSheet(props: {
193
readonly environmentId: EnvironmentId;
194
readonly item: LinkRequestItem;
@@ -251,17 +215,22 @@ function LinkRequestSheet(props: {
215
reportDefect: false,
216
});
217
const selected = choice ?? linkRequestInitialMachine(item, machines);
254
- const target = resolveTarget(item, machines, selected);
218
+ const target = linkRequestTarget(item, machines, selected);
219
const targetName = target.kind === "machine" ? target.label : linkRequestTargetName(item);
256
- // This phone can mint a code there when it is connected to that environment
257
- // with a session that may create pairing links.
220
const targetId = target.kind === "machine" ? target.environmentId : null;
221
const connected = usePreparedConnection(targetId);
222
const mayMint = useEnvironmentScope(targetId, AuthAccessWriteScope);
261
- const canMint =
262
- targetId !== null && Option.isSome(connected) && mayMint && !mintFailed.has(targetId);
223
const needsAddress =
224
target.kind === "address" || (target.kind === "machine" && target.urls.length === 0);
225
+ // This phone mints a code there when it is connected with a session that may
226
+ // create pairing links, and only for its own addresses: anything can answer
227
+ // as that machine at one typed in, so that one gets a code the user fetched.
228
+ const canMint =
229
+ targetId !== null &&
230
+ !needsAddress &&
231
+ Option.isSome(connected) &&
232
+ mayMint &&
233
+ !mintFailed.has(targetId);
234
const useExisting = target.kind === "machine" && target.linked;
235
const ready =
236
target.kind !== "none" &&
@@ -288,10 +257,7 @@ function LinkRequestSheet(props: {
257
}
258
return linkRequestAnswerInput(item, {
259
type: "link",
291
- target:
292
- target.kind === "address"
293
- ? { url: address }
294
- : { ...target, urls: needsAddress ? [address.trim()] : target.urls },
260
+ target: target.kind === "machine" && target.urls.length > 0 ? target : { url: address },
261
access,
262
pairingCode: code,
263
});
@@ -335,12 +301,27 @@ function LinkRequestSheet(props: {
301
Agents here can then launch, message and wait on threads there. It appears in that
302
machine's Connections, where it can be revoked.
303
</Text>
338
- {!pickMachine && item.url !== undefined ? (
304
+ {item.url !== undefined && target.kind === "machine" ? (
305
<Text className="font-sans text-xs text-foreground-muted" numberOfLines={1}>
306
{item.url}
307
</Text>
308
) : null}
309
</View>
310
+ {needsAddress && !useExisting && address.trim() ? (
311
+ <View
312
+ accessibilityRole="alert"
313
+ className="gap-1 rounded-xl border border-warning-border bg-warning p-3"
314
+ >
315
+ <Text className="font-t3-bold text-sm text-warning-foreground">Check this address</Text>
316
+ <Text className="font-sans text-xs leading-snug text-warning-foreground">
317
+ This app cannot confirm it is one of your machines. The pairing code you paste is sent
318
+ there.
319
+ </Text>
320
+ <Text selectable className="font-sans text-xs leading-snug text-warning-foreground">
321
+ {linkDestination(address)}
322
+ </Text>
323
+ </View>
324
+ ) : null}
325
{pickMachine ? (
326
<SettingsSection title="Machine">
327
{machines.map((machine, index) => (
@@ -369,7 +350,7 @@ function LinkRequestSheet(props: {
350
/>
351
</SettingsSection>
352
) : null}
372
- {needsAddress && !(item.url !== undefined && item.environmentId === undefined) ? (
353
+ {needsAddress && item.url === undefined ? (
354
<View className="gap-2">
355
<TextInput
356
accessibilityLabel="Address"
apps/mobile/src/lib/threadActivity.ts
+2
-1
@@ -2,6 +2,7 @@ import type {
2
ThreadPendingApproval,
3
ThreadPendingUserInput,
4
} from "@t3tools/client-runtime/state/thread-requests";
5
+import { linkRequestTargetName } from "@t3tools/client-runtime/link-request";
6
import { turnItemIsWorkspacePreparation } from "@t3tools/client-runtime/state/turn-item-presentation";
7
import type { ThreadCheckpointSummary } from "@t3tools/client-runtime/state/thread-checkpoints";
8
import { formatSubagentDisplayTitle } from "@t3tools/client-runtime/state/subagent-display";
@@ -624,7 +625,7 @@ function itemSummary(
625
case "secret_request":
626
return item.label;
627
case "link_request":
627
- return `Link ${item.label ?? item.url ?? "an environment"}`;
628
+ return `Link ${linkRequestTargetName(item)}`;
629
case "dynamic_tool": {
630
const classified = classifyToolActivity({
631
itemType: "dynamic_tool_call",
apps/server/src/mcp/OrchestratorMcpService.ts
+2
-2
@@ -969,8 +969,8 @@ function turnItemText(item: OrchestrationV2TurnItem): string | null {
969
return `Asked the user for ${item.label}: ${item.secretStatus}.`;
970
case "link_request":
971
return item.linkStatus === "linked"
972
- ? `Linked ${item.linkedLabel ?? item.label ?? item.url ?? "an environment"} (${item.linkedAccess}).`
973
- : `Asked the user to link ${item.label ?? item.url ?? "an environment"}: ${item.linkStatus}.`;
972
+ ? `Linked ${item.linkedLabel ?? item.url ?? "an environment"} (${item.linkedAccess}).`
973
+ : `Asked the user to link ${item.url ?? "an environment"}: ${item.linkStatus}.`;
974
case "subagent":
975
return item.result ?? item.progress ?? item.prompt;
976
case "dynamic_tool":
apps/server/src/peer/PeerLinkRequests.test.ts
+43
-4
@@ -469,14 +469,14 @@ it.live("the agent asks without waiting, and the user links the box after its tu
469
// The call returns at once: no tool call outlives a provider's timeout.
470
expect(asked.isError).toBe(false);
471
expect(asked.structuredContent).toEqual({ status: "pending", turnItemId: card.id });
472
- // The card names the box, found by asking its address.
472
expect(card).toMatchObject({
473
url: b.url,
474
reason: "Run the suite on the box.",
476
- environmentId: box.environmentId,
477
- label: "Box",
475
requestedAccess: "approval-required",
476
});
477
+ // Anything can answer at an address as the box, so the card names no machine.
478
+ expect(card.environmentId).toBeUndefined();
479
+ expect(card.label).toBeUndefined();
480
// The agent waits on the user, so the thread asks for input.
481
expect((yield* a.orchestrator.getThreadShell(threadId))?.pendingRuntimeRequest).toMatchObject(
482
{ kind: "user_input" },
@@ -675,7 +675,7 @@ it.live("a declined request links nothing and tells the agent", () =>
675
const { messages } = yield* outcomeMessages(a);
676
expect(messages).toHaveLength(1);
677
expect(messages[0]).toMatchObject({
678
- notification: { outcome: "cancelled", summary: "Declined to link Box" },
678
+ notification: { outcome: "cancelled", summary: `Declined to link ${b.url}` },
679
});
680
expect(messages[0]!.text).toContain("declined");
681
}),
@@ -904,6 +904,45 @@ it.live("a code the box refuses fails the request with its reason, and links not
904
),
905
);
906
907
+it.live("a card an older server left naming a machine beside its address links no machine", () =>
908
+ withBoth((a, b) =>
909
+ Effect.gen(function* () {
910
+ yield* seedThread(a);
911
+ yield* a.orchestrator.dispatch({
912
+ type: "link_request.record",
913
+ commandId: CommandId.make("command:pending:older"),
914
+ threadId,
915
+ runId,
916
+ nodeId: rootNode,
917
+ turnItemId: TurnItemId.make("turn-item:link-request:older"),
918
+ url: b.url,
919
+ environmentId: box.environmentId,
920
+ label: "Box",
921
+ reason: "",
922
+ linkStatus: "pending",
923
+ });
924
+ const card = yield* pendingCard(a);
925
+ // An older client takes the machine from the card and mints a code on it.
926
+ const pairing = yield* b.auth.issuePairingCredential();
927
+ yield* a.requests.answer({
928
+ threadId,
929
+ turnItemId: card.id,
930
+ answer: {
931
+ type: "link",
932
+ environmentId: box.environmentId,
933
+ label: "Box",
934
+ urls: [b.url],
935
+ access: "auto",
936
+ pairingCode: pairing.credential,
937
+ },
938
+ });
939
+ expect(yield* cardOf(a)).toMatchObject({ linkStatus: "failed" });
940
+ expect(Option.isNone(yield* a.links.get(box.environmentId))).toBe(true);
941
+ expect(yield* b.linkedSessions).toEqual([]);
942
+ }),
943
+ ),
944
+);
945
+
946
it.live("an agent below full access may not ask, and no card is shown", () =>
947
withBoth((a, b) =>
948
Effect.gen(function* () {
apps/server/src/peer/PeerLinkRequests.ts
+20
-15
@@ -39,7 +39,7 @@ type LinkRequestItem = Extract<OrchestrationV2TurnItem, { readonly type: "link_r
39
/** The request as it was asked, which every update of its card repeats. */
40
type LinkRequestAsk = Pick<
41
LinkRequestItem,
42
- "id" | "threadId" | "url" | "reason" | "environmentId" | "label" | "hint" | "requestedAccess"
42
+ "id" | "threadId" | "url" | "reason" | "environmentId" | "hint" | "requestedAccess"
43
> & { readonly runId: RunId; readonly nodeId: NodeId };
44
45
/** The notification that tells the agent how its card ended. */
@@ -129,7 +129,6 @@ const make = Effect.gen(function* () {
129
...(card.url === undefined ? {} : { url: card.url }),
130
reason: card.reason,
131
...(card.environmentId === undefined ? {} : { environmentId: card.environmentId }),
132
- ...(card.label === undefined ? {} : { label: card.label }),
132
...(card.hint === undefined ? {} : { hint: card.hint }),
133
...(card.requestedAccess === undefined ? {} : { requestedAccess: card.requestedAccess }),
134
...outcome,
@@ -252,9 +251,8 @@ const make = Effect.gen(function* () {
251
"Asking to link an environment requires an active run owned by this MCP provider session.",
252
});
253
}
255
- // Best effort: the card names the machine at an address the agent was
256
- // given, and the client finds it by id.
257
- const peer = input.url === undefined ? Option.none() : yield* peerLinks.describe(input.url);
254
+ // Anything can answer at an address as any machine, so a card for an
255
+ // address names none. The client names it from addresses it already has.
256
yield* record(
257
{
258
id: turnItemId,
@@ -263,11 +261,7 @@ const make = Effect.gen(function* () {
261
nodeId: run.rootNodeId,
262
...(input.url === undefined ? {} : { url: input.url }),
263
reason: input.reason ?? "",
266
- ...(Option.isSome(peer)
267
- ? { environmentId: peer.value.environmentId, label: peer.value.label }
268
- : input.environmentId === undefined
269
- ? {}
270
- : { environmentId: input.environmentId }),
264
+ ...(input.environmentId === undefined ? {} : { environmentId: input.environmentId }),
265
...(input.hint === undefined ? {} : { hint: input.hint }),
266
...(input.requestedAccess === undefined
267
? {}
@@ -357,7 +351,18 @@ const make = Effect.gen(function* () {
351
if (card.linkStatus !== "pending") {
352
return yield* new PeerLinkRequestError({ reason: "already_answered" });
353
}
360
- const outcome = yield* answerOutcome(input.answer);
354
+ // An id beside an address is what answered there, recorded by an older
355
+ // server. Linking that machine could send its pairing code to the address.
356
+ const outcome: LinkRequestOutcome =
357
+ card.url !== undefined &&
358
+ card.environmentId !== undefined &&
359
+ input.answer.type === "link" &&
360
+ input.answer.environmentId !== undefined
361
+ ? {
362
+ linkStatus: "failed",
363
+ failure: "This request is from before an update. Ask for the link again.",
364
+ }
365
+ : yield* answerOutcome(input.answer);
366
// If Stop closed the card while linking, the card keeps that; the link
367
// itself stands and Settings lists it.
368
yield* record(
@@ -416,16 +421,16 @@ const resultOf = (card: LinkRequestItem): OrchestratorMcpEnvironmentLinkResult =
421
}
422
};
423
419
-/** What the agent's words call the target: its name, its address, or the user's pick. */
420
-const linkTarget = (card: Pick<LinkRequestItem, "url" | "label" | "environmentId">) =>
421
- card.label ?? card.url ?? card.environmentId ?? "a machine";
424
+/** What the agent's words call the target: its address, its id, or the user's pick. */
425
+const linkTarget = (card: Pick<LinkRequestItem, "url" | "environmentId">) =>
426
+ card.url ?? card.environmentId ?? "a machine";
427
428
/**
429
* The notification an answer sends the agent: what the card says, and what
430
* to do next. It carries the outcome only, never the pairing code.
431
*/
432
const outcomeNotice = (
428
- card: Pick<LinkRequestItem, "url" | "label" | "environmentId">,
433
+ card: Pick<LinkRequestItem, "url" | "environmentId">,
434
outcome: LinkRequestOutcome,
435
): Omit<LinkRequestWake, "messageId"> => {
436
const target = linkTarget(card);
apps/server/src/peer/PeerLinks.test.ts
+25
@@ -603,10 +603,35 @@ it.effect(
603
expectedEnvironmentId: box.environmentId,
604
});
605
expect(linked).toMatchObject({ environmentId: box.environmentId, urls: [b.url] });
606
+ // A picked machine is never linked at this machine's own loopback.
607
+ const own = yield* a.links
608
+ .link({
609
+ url: b.url.replace("127.0.0.1", "localhost"),
610
+ pairingCode: pairing.credential,
611
+ access: "auto",
612
+ expectedEnvironmentId: box.environmentId,
613
+ })
614
+ .pipe(Effect.flip);
615
+ expect(own.message).toContain("is this machine");
616
yield* probe(a);
617
expect(yield* linkedSessions(impostor)).toEqual([]);
618
expect(yield* Ref.get(impostor.bearers)).toEqual([]);
619
expect((yield* linkedSessions(b)).length).toBe(1);
620
+
621
+ // An address alone that answers as the linked box never takes over its link.
622
+ yield* Ref.set(impostor.descriptor, box);
623
+ const second = yield* impostor.auth.issuePairingCredential();
624
+ const taken = yield* a.links
625
+ .link({ url: impostor.url, pairingCode: second.credential, access: "auto" })
626
+ .pipe(Effect.flip);
627
+ expect(taken.message).toContain("already linked");
628
+ expect(yield* linkedSessions(impostor)).toEqual([]);
629
+ expect(Option.getOrUndefined(yield* a.links.get(box.environmentId))?.urls).toEqual([b.url]);
630
+ // The address the link already has still renews it.
631
+ const renewal = yield* b.auth.issuePairingCredential();
632
+ expect(
633
+ yield* a.links.link({ url: b.url, pairingCode: renewal.credential, access: "auto" }),
634
+ ).toMatchObject({ urls: [b.url] });
635
}),
636
).pipe(Effect.provide(NodeHttpServer.layerTest)),
637
);
apps/server/src/peer/PeerLinks.testkit.ts
+2
@@ -184,6 +184,8 @@ export const layerLinkingEnvironment = <E = never>(
184
Layer.provideMerge(ServerSettings.layerTest({ linkedEnvironmentsEnabled: true })),
185
Layer.provideMerge(database),
186
Layer.provide(Layer.mergeAll(secrets, FetchHttpClient.layer)),
187
+ // Peers here are served on 127.0.0.1, so only `localhost` stands for this machine.
188
+ Layer.provide(Layer.succeed(PeerLinks.LoopbackHost, (host) => host === "localhost")),
189
// Services that act for this environment, such as delegation, name it too.
190
Layer.provideMerge(
191
Layer.succeed(ServerEnvironment.ServerEnvironment, {
apps/server/src/peer/PeerLinks.ts
+34
-21
@@ -92,15 +92,6 @@ export class PeerLinks extends Context.Service<
92
/** Whether the Linked environments beta (Settings → Labs) is on here. */
93
readonly enabled: Effect.Effect<boolean>;
94
readonly link: (input: PeerLinkCreateInput) => Effect.Effect<PeerLink, PeerLinkError>;
95
- /**
96
- * The environment answering at `url`, or nothing when it is not a usable
97
- * address or does not answer as T3 Code. Sends no credential.
98
- */
99
- readonly describe: (
100
- url: string,
101
- ) => Effect.Effect<
102
- Option.Option<{ readonly environmentId: EnvironmentId; readonly label: string }>
103
- >;
95
readonly list: Effect.Effect<ReadonlyArray<PeerLinkSummary>, PeerLinkError>;
96
/** The stored link, without asking the peer whether it answers. */
97
readonly get: (
@@ -182,6 +173,12 @@ const peerOrigin = (url: string) => {
173
return Effect.succeed(parsed.origin);
174
};
175
176
+/** Whether a host is this machine's own loopback. Tests serve their peers there, so they narrow it. */
177
+export const LoopbackHost = Context.Reference<(host: string) => boolean>(
178
+ "t3/peer/PeerLinks/LoopbackHost",
179
+ { defaultValue: () => isLocalLoopbackHost },
180
+);
181
+
182
/** Whether a peer holds a linked agent to its limits and keeps its work within its link. */
183
const linkLimitsHold = (peer: { readonly capabilities: ExecutionEnvironmentCapabilities }) =>
184
peer.capabilities.mcpModeLimitHeader === true && peer.capabilities.linkFence === true;
@@ -194,6 +191,7 @@ const make = Effect.gen(function* () {
191
const httpClient = yield* HttpClient.HttpClient;
192
const environment = yield* ServerEnvironment.ServerEnvironment;
193
const serverSettings = yield* ServerSettings.ServerSettingsService;
194
+ const isOwnLoopback = yield* LoopbackHost;
195
const enabled = serverSettings.getSettings.pipe(
196
Effect.map((settings) => settings.linkedEnvironmentsEnabled),
197
Effect.orElseSucceed(() => false),
@@ -409,6 +407,13 @@ const make = Effect.gen(function* () {
407
(url) =>
408
Effect.gen(function* () {
409
const origin = yield* peerOrigin(url);
410
+ // Loopback is this machine, where anything may answer as the one picked.
411
+ if (isOwnLoopback(new URL(origin).hostname)) {
412
+ return yield* new PeerLinkError({
413
+ reason: "unreachable",
414
+ message: `${origin} is this machine, not ${name}.`,
415
+ });
416
+ }
417
return { origin, descriptor: yield* describe(origin) };
418
}).pipe(Effect.result),
419
{ concurrency: "unbounded" },
@@ -457,8 +462,8 @@ const make = Effect.gen(function* () {
462
return yield* new PeerLinkError({ reason: "disabled", message: LINKED_ENVIRONMENTS_OFF });
463
}
464
const urls = [input.url, ...(input.alternateUrls ?? [])];
460
- // The user picked a machine: link through the addresses that prove to
461
- // be it, so a reused LAN address never receives the pairing code.
465
+ // The user picked a machine: link through the addresses that answer as
466
+ // it, so one that now answers as another never receives the pairing code.
467
const { primary, peer, origins } =
468
input.expectedEnvironmentId === undefined
469
? yield* answeringAt(urls)
@@ -467,6 +472,22 @@ const make = Effect.gen(function* () {
472
input.expectedEnvironmentId,
473
input.expectedLabel ?? input.expectedEnvironmentId,
474
);
475
+ // Anything can answer as a linked machine, so an address alone renews its
476
+ // link only where the link already reaches it, and never moves it.
477
+ if (input.expectedEnvironmentId === undefined) {
478
+ const row = yield* readRow(peer.environmentId);
479
+ const existing = Option.isSome(row) ? yield* toLink(row.value) : undefined;
480
+ if (
481
+ existing !== undefined &&
482
+ DateTime.isGreaterThan(existing.expiresAt, yield* DateTime.now) &&
483
+ !existing.urls.includes(primary)
484
+ ) {
485
+ return yield* new PeerLinkError({
486
+ reason: "pairing_rejected",
487
+ message: `${primary} answers as ${existing.label}, which is already linked at another address. If ${existing.label} moved, forget that link first.`,
488
+ });
489
+ }
490
+ }
491
const self = yield* environment.getDescriptor;
492
if (peer.environmentId === self.environmentId) {
493
return yield* new PeerLinkError({
@@ -532,13 +553,6 @@ const make = Effect.gen(function* () {
553
return linked;
554
});
555
535
- const describeUrl: PeerLinks["Service"]["describe"] = (url) =>
536
- peerOrigin(url).pipe(
537
- Effect.flatMap(describe),
538
- Effect.map(Option.map((peer) => ({ environmentId: peer.environmentId, label: peer.label }))),
539
- Effect.orElseSucceed(() => Option.none()),
540
- );
541
-
556
/** A peer's label follows its machine name, so the link takes the one its own address answers with. */
557
const withLabel = (link: PeerLink, label: string) =>
558
label === link.label
@@ -621,8 +635,8 @@ const make = Effect.gen(function* () {
635
message: `The link to ${link.label} lost its credential. Link it again.`,
636
});
637
}
624
- // The token goes only to an address that proves it is this peer, so a
625
- // reused LAN address or a moved hostname never receives it.
638
+ // The token goes only to an address that still answers as this peer,
639
+ // so one that now answers as another machine never receives it.
640
let fenced = true;
641
let label = link.label;
642
const url = yield* Effect.findFirst(link.urls, (candidate) =>
@@ -678,7 +692,6 @@ const make = Effect.gen(function* () {
692
return PeerLinks.of({
693
enabled,
694
link,
681
- describe: describeUrl,
695
list,
696
get,
697
unlink,
apps/web/src/components/chat/LinkRequestCard.tsx
+17
-50
@@ -1,6 +1,7 @@
1
import { pipe } from "effect/Function";
2
import { useAtomValue } from "@effect/atom-react";
3
import {
4
+ ANOTHER_ADDRESS,
5
type LinkableMachine,
6
linkRequestAnswerInput,
7
linkRequestDefaultAccess,
@@ -8,6 +9,7 @@ import {
9
linkRequestFailureMessage,
10
linkRequestInitialMachine,
11
type LinkRequestItem,
12
+ linkRequestTarget,
13
linkRequestTargetName,
14
rankMachinesByHint,
15
} from "@t3tools/client-runtime/link-request";
@@ -33,7 +35,7 @@ import { useAtomCommand } from "../../state/use-atom-command";
35
import { accessConfig } from "../auth/ConnectAgentSurface";
36
import { EnvironmentMachineIcon } from "../EnvironmentMachineIcon";
37
import { LinkAccessPicker } from "../settings/LinkAccessPicker";
36
-import { ANOTHER_ADDRESS, LinkMachineBadge } from "../settings/LinkMachineSelect";
38
+import { LinkAddressWarning, LinkMachineBadge } from "../settings/LinkMachineSelect";
39
import { Button } from "../ui/button";
40
import { Dialog } from "../ui/dialog";
41
import { Input } from "../ui/input";
@@ -122,9 +124,6 @@ function PendingLinkRequest(props: {
124
: `Link ${target} to this environment`}
125
</p>
126
{item.reason.trim() ? <p className="text-sm text-muted-foreground">{item.reason}</p> : null}
125
- {item.label !== undefined && item.url !== undefined ? (
126
- <p className="truncate text-xs text-muted-foreground/80">{item.url}</p>
127
- ) : null}
127
</div>
128
{error !== null ? (
129
<p role="alert" className="text-xs text-destructive">
@@ -161,41 +160,6 @@ function PendingLinkRequest(props: {
160
);
161
}
162
164
-/**
165
- * What the dialog links: a machine from the client's catalog, or an address.
166
- * `urls` is empty when the client knows no direct address for the machine,
167
- * so the user types one.
168
- */
169
-type DialogTarget =
170
- | { readonly kind: "none" }
171
- | {
172
- readonly kind: "machine";
173
- readonly environmentId: EnvironmentId;
174
- readonly label: string;
175
- readonly urls: ReadonlyArray<string>;
176
- readonly linked: boolean;
177
- }
178
- | { readonly kind: "address" };
179
-
180
-function resolveTarget(
181
- item: LinkRequestItem,
182
- machines: ReadonlyArray<LinkableMachine>,
183
- choice: string | null,
184
-): DialogTarget {
185
- if (item.environmentId === undefined && item.url !== undefined) return { kind: "address" };
186
- const chosen = item.environmentId ?? choice;
187
- if (chosen === null) return { kind: "none" };
188
- if (chosen === ANOTHER_ADDRESS) return { kind: "address" };
189
- const machine = machines.find((candidate) => candidate.environmentId === chosen);
190
- return {
191
- kind: "machine",
192
- environmentId: machine?.environmentId ?? (chosen as EnvironmentId),
193
- label: machine?.label ?? linkRequestTargetName(item),
194
- urls: [...new Set([...(machine?.urls ?? []), ...(item.url === undefined ? [] : [item.url])])],
195
- linked: machine?.linked ?? false,
196
- };
197
-}
198
-
163
/** The dialog's steps: where to link, then what agents may do there. */
164
type LinkStep = "machine" | "access";
165
@@ -229,19 +193,24 @@ function LinkRequestDialog(props: {
193
reportDefect: false,
194
});
195
const selected = choice ?? linkRequestInitialMachine(item, machines);
232
- const target = resolveTarget(item, machines, selected);
196
+ const target = linkRequestTarget(item, machines, selected);
197
const targetName = target.kind === "machine" ? target.label : linkRequestTargetName(item);
234
- // This client can mint a code there when it is connected to that
235
- // environment with a session that may create pairing links.
198
const targetId = target.kind === "machine" ? target.environmentId : null;
199
const connected = usePreparedConnection(targetId);
200
const mayMint = useEnvironmentScope(targetId, AuthAccessWriteScope);
239
- const canMint =
240
- targetId !== null && Option.isSome(connected) && mayMint && !mintFailed.has(targetId);
201
const needsAddress =
202
target.kind === "address" || (target.kind === "machine" && target.urls.length === 0);
203
+ // This client mints a code there when it is connected with a session that may
204
+ // create pairing links, and only for its own addresses: anything can answer
205
+ // as that machine at one typed in, so that one gets a code the user fetched.
206
+ const canMint =
207
+ targetId !== null &&
208
+ !needsAddress &&
209
+ Option.isSome(connected) &&
210
+ mayMint &&
211
+ !mintFailed.has(targetId);
212
// An address the agent gave is already filled in; only one the user must type is asked for.
244
- const asksAddress = needsAddress && !(item.url !== undefined && item.environmentId === undefined);
213
+ const asksAddress = needsAddress && item.url === undefined;
214
const useExisting = target.kind === "machine" && target.linked;
215
// A named machine with an address it answers at has nothing to choose before access.
216
const steps: ReadonlyArray<LinkStep> =
@@ -287,10 +256,7 @@ function LinkRequestDialog(props: {
256
}
257
return linkRequestAnswerInput(item, {
258
type: "link",
290
- target:
291
- target.kind === "address"
292
- ? { url: address }
293
- : { ...target, urls: needsAddress ? [address.trim()] : target.urls },
259
+ target: target.kind === "machine" && target.urls.length > 0 ? target : { url: address },
260
access,
261
pairingCode: code,
262
});
@@ -393,11 +359,12 @@ function LinkRequestDialog(props: {
359
</>
360
) : (
361
<>
396
- {item.url !== undefined && !pickMachine ? (
362
+ {item.url !== undefined && target.kind === "machine" ? (
363
<p className="truncate text-xs text-muted-foreground">{item.url}</p>
364
) : null}
365
{useExisting ? null : (
366
<>
367
+ {needsAddress ? <LinkAddressWarning address={address} /> : null}
368
{canMint ? null : (
369
<label className="block space-y-1.5">
370
<span className="block text-xs font-medium text-foreground">
apps/web/src/components/settings/LinkMachineSelect.tsx
+22
-3
@@ -1,12 +1,31 @@
1
-import type { LinkableMachine } from "@t3tools/client-runtime/link-request";
1
+import {
2
+ ANOTHER_ADDRESS,
3
+ type LinkableMachine,
4
+ linkDestination,
5
+} from "@t3tools/client-runtime/link-request";
6
import { useId } from "react";
7
8
import { EnvironmentMachineIcon } from "../EnvironmentMachineIcon";
9
+import { Alert, AlertDescription, AlertTitle } from "../ui/alert";
10
import { Badge } from "../ui/badge";
11
import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select";
12
8
-/** The machine choice for linking by an address typed in. */
9
-export const ANOTHER_ADDRESS = "another-address";
13
+/**
14
+ * Shown wherever a link goes to an address this app does not already have for a
15
+ * machine, with where that address leads.
16
+ */
17
+export function LinkAddressWarning({ address }: { readonly address: string }) {
18
+ return (
19
+ <Alert variant="warning">
20
+ <AlertTitle>Check this address</AlertTitle>
21
+ <AlertDescription>
22
+ This app cannot confirm it is one of your machines. The pairing code you paste is sent
23
+ there.
24
+ <span className="block break-all">{linkDestination(address)}</span>
25
+ </AlertDescription>
26
+ </Alert>
27
+ );
28
+}
29
30
/** Whether a machine is linked already, or how this app knows it when not connected to it. */
31
export function LinkMachineBadge({ machine }: { readonly machine: LinkableMachine }) {
apps/web/src/components/settings/LinkedEnvironmentsSettings.tsx
+15
-7
@@ -1,5 +1,5 @@
1
import { useAtomValue } from "@effect/atom-react";
2
-import { linkRequestFailureMessage } from "@t3tools/client-runtime/link-request";
2
+import { ANOTHER_ADDRESS, linkRequestFailureMessage } from "@t3tools/client-runtime/link-request";
3
import {
4
AuthAccessWriteScope,
5
type AuthMcpClientAccess,
@@ -41,7 +41,7 @@ import { Input } from "../ui/input";
41
import { stackedThreadToast, toastManager } from "../ui/toast";
42
import { ITEM_ROW_CLASSNAME, ITEM_ROW_INNER_CLASSNAME } from "./itemRows";
43
import { LinkAccessPicker } from "./LinkAccessPicker";
44
-import { ANOTHER_ADDRESS, LinkMachineSelect } from "./LinkMachineSelect";
44
+import { LinkAddressWarning, LinkMachineSelect } from "./LinkMachineSelect";
45
import { SettingsRow, SettingsSection } from "./settingsLayout";
46
import { useNowMinute } from "../../hooks/useNowMinute";
47
import { searchableSetting } from "./settingsSearch";
@@ -183,14 +183,20 @@ function LinkEnvironmentAction({ environmentId }: { readonly environmentId: Envi
183
const link = useAtomCommand(peerLinkEnvironment.link, { label: "link environment" });
184
const selected = choice ?? (machines.length === 0 ? ANOTHER_ADDRESS : null);
185
const machine = machines.find((candidate) => candidate.environmentId === selected) ?? null;
186
- // This client can mint a code there when it is connected to that
187
- // environment with a session that may create pairing links.
186
const targetId = machine?.environmentId ?? null;
187
const connected = usePreparedConnection(targetId);
188
const mayMint = useEnvironmentScope(targetId, AuthAccessWriteScope);
189
+ // A picked machine that left the list has no address here either.
190
+ const needsAddress = selected !== null && (machine === null || machine.urls.length === 0);
191
+ // This client mints a code there when it is connected with a session that may
192
+ // create pairing links, and only for its own addresses: anything can answer
193
+ // as that machine at one typed in, so that one gets a code the user fetched.
194
const canMint =
192
- targetId !== null && Option.isSome(connected) && mayMint && !mintFailed.has(targetId);
193
- const needsAddress = selected === ANOTHER_ADDRESS || machine?.urls.length === 0;
195
+ targetId !== null &&
196
+ !needsAddress &&
197
+ Option.isSome(connected) &&
198
+ mayMint &&
199
+ !mintFailed.has(targetId);
200
const ready =
201
selected !== null &&
202
(!needsAddress || address.trim().length > 0) &&
@@ -229,7 +235,8 @@ function LinkEnvironmentAction({ environmentId }: { readonly environmentId: Envi
235
input: {
236
url,
237
...(alternateUrls.length > 0 ? { alternateUrls } : {}),
232
- ...(machine === null
238
+ // A typed address links alone: only this app's own addresses name a machine.
239
+ ...(machine === null || needsAddress
240
? {}
241
: { expectedEnvironmentId: machine.environmentId, expectedLabel: machine.label }),
242
pairingCode: code,
@@ -317,6 +324,7 @@ function LinkEnvironmentAction({ environmentId }: { readonly environmentId: Envi
324
) : null}
325
</label>
326
) : null}
327
+ {needsAddress && address.trim() ? <LinkAddressWarning address={address} /> : null}
328
{selected === null || canMint ? null : (
329
<label className="block space-y-1.5">
330
<span className="block text-xs font-medium text-foreground">Pairing code</span>
docs/internals/remote.md
+9
-3
@@ -94,9 +94,15 @@ Unlinking on the linking side only forgets the token.
94
`T3-Mode-Limit`, which the receiving `/mcp` only ever narrows the client's
95
approved access with. A plan-mode agent therefore cannot start full-access
96
work through a full-access link.
97
-- **The token goes only to an address that proves it is the linked
98
- environment**: its descriptor must report the linked environment id. A LAN
99
- address that now belongs to another machine never receives it.
97
+- **A descriptor's environment id filters addresses; it does not prove
98
+ identity.** The token goes only to an address that reports the linked id, so
99
+ a LAN address that now reports another machine's never receives it. Anything can
100
+ report any id, though, so only addresses from the user's client count as a
101
+ machine's, and never a loopback one, which names whichever machine opens
102
+ it. An address an agent gives is recorded alone, and
103
+ [`linkRequestTarget`](../../packages/client-runtime/src/linkRequest.ts) names
104
+ a machine for it only when the client already reaches exactly one machine
105
+ there. An address alone never moves an unexpired link to another address.
106
- **All callers on one side share the link's single session on the other**,
107
so idempotency keys are hashed with the caller's namespace before they
108
leave. Without that, two agents reusing a key would collide on the far side.
docs/user/remote-access.md
+7
-4
@@ -333,14 +333,17 @@ off, its result arrives once it is back on.
333
On the machine you will work from, open **Settings → Environments → Linked environments**,
334
choose **Link**, and pick the other machine or enter its address. The list
335
holds the machines this app knows and those on your T3 Connect account. If this
336
-app is connected to that machine with a session that manages access there, it
337
-makes the pairing code itself; otherwise paste one from that machine's
338
-**Settings → Sharing & access**. From a terminal, use
336
+app has an address for that machine and is connected to it with a session that
337
+manages access there, it makes the pairing code itself; otherwise paste one
338
+from that machine's **Settings → Sharing & access**. An address you type always
339
+needs a pasted code. From a terminal, use
340
`t3 environment link <address> --pairing-code <code> --access <mode>`.
341
342
You can also ask an agent to link a machine by name, such as "delegate this to
343
my vps". It shows a card in the thread where you pick the machine the same way
343
-and the access, then approve.
344
+and the access, then approve. An address the agent gives that this app does
345
+not know for one of your machines also needs a pasted code. Paste one only for
346
+an address you trust: the code is sent there.
347
348
- The access you pick is the most agents from this machine may do there. An
349
agent also never gets more there than its own mode here.
packages/client-runtime/src/linkRequest.test.ts
+85
-2
@@ -8,12 +8,15 @@ import { BearerConnectionTarget, RelayConnectionTarget } from "./connection/mode
8
import type { EnvironmentPresentation } from "./connection/presentation.ts";
9
import type { RelayDiscoveredEnvironment } from "./relay/discovery.ts";
10
import {
11
+ ANOTHER_ADDRESS,
12
linkableMachines,
13
linkedEnvironmentNames,
14
linkRequestAnswerInput,
15
linkRequestDisplay,
16
linkRequestFailureMessage,
17
linkRequestInitialMachine,
18
+ linkRequestTarget,
19
+ linkRequestTargetName,
20
rankMachinesByHint,
21
} from "./linkRequest.ts";
22
@@ -187,9 +190,10 @@ const discovered = (
190
describe("linkableMachines", () => {
191
it("lists the other machines with reported addresses before saved ones, once each", () => {
192
const here = presentation("environment-here", "Here", { saved: ["http://localhost:3773"] });
193
+ // A loopback address would name the linking server itself, so it is no address of the VPS.
194
const vps = presentation("environment-vps", "VPS", {
191
- saved: ["https://vps.example.com", "https://vps.ts.net"],
192
- reported: ["https://vps.ts.net"],
195
+ saved: ["https://vps.example.com", "https://vps.ts.net", "http://127.0.0.1:3773"],
196
+ reported: ["https://vps.ts.net", "http://localhost:3773"],
197
});
198
const mini = presentation("environment-mini", "Mini", { connected: false });
199
expect(
@@ -312,6 +316,24 @@ describe("linkableMachines", () => {
316
urls: ["https://environment-mini.t3.example"],
317
});
318
expect(listed[2]).toMatchObject({ machine: "server", linked: true });
319
+
320
+ // A Connect record that publishes only a loopback address gives the machine none.
321
+ const local = discovered("environment-local", "Local");
322
+ const published = {
323
+ ...local,
324
+ environment: {
325
+ ...local.environment,
326
+ endpoint: { ...local.environment.endpoint, httpBaseUrl: "http://127.0.0.1:3773/" },
327
+ },
328
+ };
329
+ expect(
330
+ linkableMachines({
331
+ environments: [],
332
+ threadEnvironmentId: EnvironmentId.make("environment-here"),
333
+ links: [],
334
+ connect: new Map([["environment-local", published]]),
335
+ })[0]?.urls,
336
+ ).toEqual([]);
337
});
338
});
339
@@ -392,6 +414,67 @@ describe("rankMachinesByHint", () => {
414
});
415
});
416
417
+describe("linkRequestTarget", () => {
418
+ const box = {
419
+ environmentId: EnvironmentId.make("environment-box"),
420
+ label: "Box",
421
+ machine: "server",
422
+ connected: true,
423
+ connectOnly: false,
424
+ linked: false,
425
+ urls: ["http://10.0.0.2:3773", "https://box.t3connect.example/"],
426
+ } as const;
427
+
428
+ it("takes a machine from an address the agent gave only where this app already reaches it", () => {
429
+ // Anything can answer at an address as the box, so an id beside one is not trusted.
430
+ const unfamiliar = {
431
+ url: "https://other.example",
432
+ environmentId: box.environmentId,
433
+ label: "Box",
434
+ };
435
+ expect(linkRequestTarget(unfamiliar, [box], null)).toEqual({ kind: "address" });
436
+ expect(linkRequestTarget(unfamiliar, [box], box.environmentId)).toEqual({ kind: "address" });
437
+ expect(linkRequestTargetName(unfamiliar)).toBe("https://other.example");
438
+ // A username in the address must not pass for the host the code goes to.
439
+ expect(linkRequestTargetName({ url: "https://box.t3connect.example@other.example/x" })).toBe(
440
+ "https://other.example",
441
+ );
442
+ // A known address in another spelling is the box, linked at its own addresses only.
443
+ expect(
444
+ linkRequestTarget({ url: "https://BOX.t3connect.example:443/mcp" }, [box], null),
445
+ ).toEqual({
446
+ kind: "machine",
447
+ environmentId: box.environmentId,
448
+ label: "Box",
449
+ urls: box.urls,
450
+ linked: false,
451
+ });
452
+ expect(linkRequestTarget({ url: "http://box.t3connect.example" }, [box], null)).toEqual({
453
+ kind: "address",
454
+ });
455
+ expect(linkRequestTarget({ url: "not a url" }, [box], null)).toEqual({ kind: "address" });
456
+ expect(linkRequestTarget({ url: "blob:https://box.t3connect.example/1" }, [box], null)).toEqual(
457
+ { kind: "address" },
458
+ );
459
+ // A private address two machines share names neither.
460
+ const mini = { ...box, environmentId: EnvironmentId.make("environment-mini") };
461
+ expect(linkRequestTarget({ url: "http://10.0.0.2:3773" }, [box, mini], null)).toEqual({
462
+ kind: "address",
463
+ });
464
+ });
465
+
466
+ it("links the machine the agent named or the user picked, at the addresses this app has", () => {
467
+ expect(linkRequestTarget({ environmentId: box.environmentId }, [box], null)).toMatchObject({
468
+ kind: "machine",
469
+ label: "Box",
470
+ urls: box.urls,
471
+ });
472
+ expect(linkRequestTarget({}, [box], box.environmentId)).toMatchObject({ kind: "machine" });
473
+ expect(linkRequestTarget({}, [box], ANOTHER_ADDRESS)).toEqual({ kind: "address" });
474
+ expect(linkRequestTarget({}, [box], null)).toEqual({ kind: "none" });
475
+ });
476
+});
477
+
478
describe("linkRequestFailureMessage", () => {
479
it("passes through only known user-facing errors", () => {
480
expect(
packages/client-runtime/src/linkRequest.ts
+84
-10
@@ -8,6 +8,7 @@ import {
8
resolveEnvironmentMachineKind,
9
type ServerConfig,
10
} from "@t3tools/contracts";
11
+import { isLocalLoopbackHost } from "@t3tools/shared/hostClassification";
12
import * as Option from "effect/Option";
13
14
import type { EnvironmentPresentation } from "./connection/presentation.ts";
@@ -50,9 +51,26 @@ export const linkRequestDefaultAccess = (
51
item: Pick<LinkRequestItem, "requestedAccess">,
52
): AuthMcpClientAccess => item.requestedAccess ?? "approval-required";
53
53
-/** What the card calls the other environment: its own name, else the address asked for. */
54
-export const linkRequestTargetName = (item: Pick<LinkRequestItem, "label" | "url">): string =>
55
- item.label?.trim() || item.url || "a machine";
54
+const parsedUrl = (url: string) => {
55
+ try {
56
+ return new URL(url);
57
+ } catch {
58
+ return undefined;
59
+ }
60
+};
61
+
62
+/** The http or https origin of an address: what the server links, and nothing else in it. */
63
+const originOf = (url: string) => {
64
+ const parsed = parsedUrl(url);
65
+ return parsed?.protocol === "http:" || parsed?.protocol === "https:" ? parsed.origin : undefined;
66
+};
67
+
68
+/** Where a link to `address` sends its pairing code, which a username or path in it can hide. */
69
+export const linkDestination = (address: string): string => originOf(address) ?? address.trim();
70
+
71
+/** What the card calls the other environment: where the address asked for leads, never a name it answers with. */
72
+export const linkRequestTargetName = (item: Pick<LinkRequestItem, "url">): string =>
73
+ item.url === undefined ? "a machine" : linkDestination(item.url);
74
75
/** A machine the user could link a thread's environment to. */
76
export interface LinkableMachine {
@@ -68,11 +86,17 @@ export interface LinkableMachine {
86
* Where the client knows it answers, most preferred first: the addresses it
87
* reports, then its saved routes, then its T3 Connect address. The server
88
* keeps only those that answer as this machine. Empty for a machine reached
71
- * only over SSH, whose forward lives in this client.
89
+ * only over SSH or loopback, which name this client's device.
90
*/
91
readonly urls: ReadonlyArray<string>;
92
}
93
94
+/** A loopback address names whichever machine opens it: the linking server, not this one. */
95
+const isLoopbackUrl = (url: string) => {
96
+ const hostname = parsedUrl(url)?.hostname;
97
+ return hostname !== undefined && isLocalLoopbackHost(hostname);
98
+};
99
+
100
/**
101
* The catalog's machines other than the thread's own, in catalog order, then those only T3
102
* Connect knows. `links` are the thread environment's; an expired one no longer counts as
@@ -114,7 +138,7 @@ export function linkableMachines(input: {
138
...routes,
139
...(connect === undefined ? [] : [connect.httpBaseUrl]),
140
]),
117
- ],
141
+ ].filter((url) => !isLoopbackUrl(url)),
142
};
143
});
144
const savedIds = new Set<string>(saved.map((machine) => machine.environmentId));
@@ -135,7 +159,7 @@ export function linkableMachines(input: {
159
connected: false,
160
connectOnly: true,
161
linked: linkedIds.has(environment.environmentId),
138
- urls: [environment.endpoint.httpBaseUrl],
162
+ urls: [environment.endpoint.httpBaseUrl].filter((url) => !isLoopbackUrl(url)),
163
};
164
});
165
return [...saved, ...connectOnly];
@@ -192,6 +216,59 @@ export function linkRequestInitialMachine(
216
: null;
217
}
218
219
+/** The machine choice for linking by an address typed in. */
220
+export const ANOTHER_ADDRESS = "another-address";
221
+
222
+/**
223
+ * What a link request links: a machine from the client's catalog, or an address.
224
+ * `urls` is empty when the client knows no direct address for the machine,
225
+ * so the user types one.
226
+ */
227
+export type LinkRequestTarget =
228
+ | { readonly kind: "none" }
229
+ | {
230
+ readonly kind: "machine";
231
+ readonly environmentId: EnvironmentId;
232
+ readonly label: string;
233
+ readonly urls: ReadonlyArray<string>;
234
+ readonly linked: boolean;
235
+ }
236
+ | { readonly kind: "address" };
237
+
238
+/**
239
+ * Anything can answer at an address as any machine, so an address the agent
240
+ * gave is a machine only where this client already reaches that machine. Its
241
+ * pairing code is minted for, and sent to, the client's own addresses alone.
242
+ */
243
+export function linkRequestTarget(
244
+ item: Pick<LinkRequestItem, "environmentId" | "url">,
245
+ machines: ReadonlyArray<LinkableMachine>,
246
+ choice: string | null,
247
+): LinkRequestTarget {
248
+ const asked = item.url === undefined ? undefined : originOf(item.url);
249
+ // Two machines on separate networks can share a private address.
250
+ const [reached, ...others] =
251
+ asked === undefined
252
+ ? []
253
+ : machines.filter((machine) => machine.urls.some((url) => originOf(url) === asked));
254
+ const chosen =
255
+ item.url === undefined
256
+ ? (item.environmentId ?? choice)
257
+ : reached !== undefined && others.length === 0
258
+ ? reached.environmentId
259
+ : ANOTHER_ADDRESS;
260
+ if (chosen === null) return { kind: "none" };
261
+ if (chosen === ANOTHER_ADDRESS) return { kind: "address" };
262
+ const machine = machines.find((candidate) => candidate.environmentId === chosen);
263
+ return {
264
+ kind: "machine",
265
+ environmentId: machine?.environmentId ?? (chosen as EnvironmentId),
266
+ label: machine?.label ?? linkRequestTargetName(item),
267
+ urls: machine?.urls ?? [],
268
+ linked: machine?.linked ?? false,
269
+ };
270
+}
271
+
272
/** What a link request card shows: the actions while pending, otherwise a one-line outcome. */
273
export type LinkRequestDisplay =
274
| { readonly kind: "pending" }
@@ -208,10 +285,7 @@ export type LinkRequestDisplay =
285
* names an access level the way the client's access picker does.
286
*/
287
export function linkRequestDisplay(
211
- item: Pick<
212
- LinkRequestItem,
213
- "linkStatus" | "label" | "url" | "linkedLabel" | "linkedAccess" | "failure"
214
- >,
288
+ item: Pick<LinkRequestItem, "linkStatus" | "url" | "linkedLabel" | "linkedAccess" | "failure">,
289
visibility: "local" | "inherited" | "synthetic",
290
accessLabel: (access: AuthMcpClientAccess) => string,
291
): LinkRequestDisplay {
packages/contracts/src/orchestrationV2.ts
+3
-2
@@ -1603,8 +1603,9 @@ const OrchestrationV2LinkRequestFields = {
1603
url: Schema.optional(TrimmedNonEmptyString),
1604
reason: Schema.String,
1605
/**
1606
- * The environment the agent named, or the one answering at `url`. Without
1607
- * either the user picks the machine in the card.
1606
+ * The environment the agent named. Without it or `url` the user picks the
1607
+ * machine in the card. Beside a `url`, this and `label` are what answered
1608
+ * there on an older server: unauthenticated, so clients ignore both.
1609
*/
1610
environmentId: Schema.optional(EnvironmentId),
1611
label: Schema.optional(Schema.String),