Skip to content

Commit 5e9d564

Browse files
feat(server,web,mobile): @-mention a machine, and linked environments become a Labs beta (#17130)
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 8b14660 commit 5e9d564

65 files changed

Lines changed: 1174 additions & 45 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
506 Bytes
Loading

‎apps/mobile/scripts/sync-context-chip-icons.mjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const lucideIcons = [
4343
"message-circle",
4444
"messages-square",
4545
"mouse-pointer-click",
46+
"server",
4647
"terminal",
4748
];
4849

‎apps/mobile/src/components/ComposerContextSheet.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@ export function ComposerContextSheet(props: {
324324
) : null}
325325
</View>
326326
) : null}
327+
{record.kind === "environment" ? (
328+
<ContextField label="Machine" value={record.label} />
329+
) : null}
327330
{record.kind === "skill" ? (
328331
<View className="gap-3">
329332
<ContextField label="Skill" value={record.name} />

‎apps/mobile/src/features/connection/LinkedEnvironmentsSection.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { offersLinkedEnvironments } from "@t3tools/client-runtime/link-request";
12
import { peerLinkHealth } from "@t3tools/client-runtime/state/peerLinks";
23
import { useFocusEffect } from "@react-navigation/native";
34
import { AuthAccessReadScope, type EnvironmentId } from "@t3tools/contracts";
@@ -18,7 +19,7 @@ export function LinkedEnvironmentsSection(props: {
1819
}) {
1920
const config = useEnvironmentServerConfig(props.environmentId);
2021
const canRead = useEnvironmentScope(props.environmentId, AuthAccessReadScope);
21-
const supported = canRead && config?.environment.capabilities.peerLinks === true;
22+
const supported = canRead && offersLinkedEnvironments(config);
2223
const links = useEnvironmentQuery(
2324
supported ? peerLinkEnvironment.list({ environmentId: props.environmentId, input: {} }) : null,
2425
);

‎apps/mobile/src/features/settings/SettingsServerControlsRouteScreen.test.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ vi.mock("../../state/session", () => ({
5757
),
5858
}));
5959
vi.mock("../../state/server", () => ({ serverEnvironment: { updateSettings: {} } }));
60+
vi.mock("../../state/environments", () => ({ useEnvironments: () => ({ environments: [] }) }));
6061
vi.mock("../../state/use-atom-command", () => ({
6162
useAtomCommand: () => mocks.updateSettings,
6263
}));

‎apps/mobile/src/features/settings/ThreadSettingsSections.tsx‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import { useSafeAreaInsets } from "react-native-safe-area-context";
1111
import { DEFAULT_SERVER_SETTINGS } from "@t3tools/contracts";
1212
import { supportsSharedSettingsSync } from "@t3tools/client-runtime/state/shared-settings";
1313
import { AppText as Text } from "../../components/ui/AppText";
14+
import { useEnvironments } from "../../state/environments";
1415
import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/preferences";
16+
import { serverEnvironment } from "../../state/server";
17+
import { useAtomCommand } from "../../state/use-atom-command";
1518
import { SettingsSection } from "./components/SettingsSection";
1619
import { SettingsSwitchRow } from "./components/SettingsSwitchRow";
1720
import { SettingsScreen } from "./components/SettingsScreen";
@@ -31,6 +34,7 @@ export function SettingsLabsRouteScreen() {
3134
contentContainerClassName="gap-6 px-5 pt-4"
3235
contentContainerStyle={{ paddingBottom: Math.max(insets.bottom, 18) + 18 }}
3336
>
37+
<BetaSettingsSection />
3438
<LegacySettingsSection />
3539
</ScrollView>
3640
</SettingsScreen>
@@ -214,6 +218,47 @@ export function NewThreadSettingsSection() {
214218
);
215219
}
216220

221+
/** Per machine, since each machine's own setting decides whether it links and answers links. */
222+
function BetaSettingsSection() {
223+
const { environments } = useEnvironments();
224+
const supported = environments.filter(
225+
(environment) =>
226+
environment.connection.phase === "connected" &&
227+
environment.serverConfig?.environment.capabilities.peerLinks === true,
228+
);
229+
const writable = useEnvironmentsWithScope(supported, AuthSettingsWriteScope);
230+
const updateSettings = useAtomCommand(serverEnvironment.updateSettings, {
231+
label: "linked environments beta update",
232+
reportFailure: true,
233+
});
234+
if (supported.length === 0) return null;
235+
return (
236+
<View className="gap-3">
237+
<SettingsSection title="Beta: Linked environments">
238+
{supported.map((environment) => (
239+
<SettingsSwitchRow
240+
key={environment.environmentId}
241+
icon="link"
242+
label={environment.label}
243+
value={environment.serverConfig?.settings.linkedEnvironmentsEnabled === true}
244+
disabled={!writable.has(environment.environmentId)}
245+
onValueChange={(value) =>
246+
void updateSettings({
247+
environmentId: environment.environmentId,
248+
input: { patch: { linkedEnvironmentsEnabled: value } },
249+
})
250+
}
251+
/>
252+
))}
253+
</SettingsSection>
254+
<Text className="px-2 text-sm text-foreground-muted">
255+
Let agents on a machine work on your other machines, and theirs on it. Turn it on for each
256+
machine. While it is off, nothing new starts over a link; tasks already running finish.
257+
</Text>
258+
</View>
259+
);
260+
}
261+
217262
function LegacySettingsSection() {
218263
const savePreferences = useAtomSet(updateMobilePreferencesAtom);
219264
const preferences = useAtomValue(mobilePreferencesAtom);

‎apps/mobile/src/features/settings/settings-search.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const SETTINGS_SEARCH_TERMS = {
8383
"submodules",
8484
"start from remote",
8585
],
86-
SettingsLabs: ["legacy", "plan mode", "beta"],
86+
SettingsLabs: ["legacy", "plan mode", "beta", "linked environments", "link machine"],
8787
SettingsEnvironmentMaintenance: ["updates", "provider updates", "restart", "manage environments"],
8888
SettingsAbout: [
8989
"version",

‎apps/mobile/src/features/threads/ComposerCommandPopover.tsx‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import {
33
type ProviderSkillSourceKind,
44
} from "@t3tools/client-runtime/providerSkills";
55
import type {
6+
EnvironmentId,
7+
EnvironmentMachineKind,
68
PullRequestContextMetadata,
79
ScopedThreadRef,
810
ServerProviderSkill,
@@ -14,6 +16,7 @@ import { Pressable, ScrollView, StyleSheet, View, type ViewStyle } from "react-n
1416

1517
import { SymbolView, type AppSymbolName } from "../../components/ui/AppSymbol";
1618
import { AppText as Text } from "../../components/ui/AppText";
19+
import { ENVIRONMENT_MACHINE_SYMBOLS } from "../../components/EnvironmentMachineSymbol";
1720
import { GlassSurface } from "../../components/ui/GlassSurface";
1821
import { PierreEntryIcon } from "../../components/PierreEntryIcon";
1922
import { pullRequestStatus } from "../pull-requests/pullRequestStatus";
@@ -40,6 +43,14 @@ export type ComposerCommandItem =
4043
readonly label: string;
4144
readonly description: string;
4245
}
46+
| {
47+
readonly id: string;
48+
readonly type: "environment";
49+
readonly environmentId: EnvironmentId;
50+
readonly machine: EnvironmentMachineKind;
51+
readonly label: string;
52+
readonly description: string;
53+
}
4354
| {
4455
readonly id: string;
4556
readonly type: "slash-command";
@@ -110,6 +121,8 @@ function itemIcon(item: ComposerCommandItem): AppSymbolName | null {
110121
return null;
111122
case "thread":
112123
return "text.bubble";
124+
case "environment":
125+
return ENVIRONMENT_MACHINE_SYMBOLS[item.machine];
113126
}
114127
}
115128

‎apps/mobile/src/features/threads/ThreadComposer.tsx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import {
6666
import { appAtomRegistry } from "../../state/atom-registry";
6767
import type { ComposerDocumentAttachment } from "../../lib/composerContext";
6868
import { useProject, useThreadShells } from "../../state/entities";
69+
import { useMentionableEnvironments } from "../../state/environments";
6970
import { scopeProjectRef } from "@t3tools/client-runtime/environment";
7071

7172
import { AppText as Text } from "../../components/ui/AppText";
@@ -99,6 +100,8 @@ import { ComposerCommandPopover } from "./ComposerCommandPopover";
99100
import { ComposerPopoverAnchor } from "./ComposerPopoverAnchor";
100101
import { ComposerQueuedEditAttachments } from "./ComposerQueuedEdit";
101102
import { useComposerCommandMenu } from "./use-composer-command-menu";
103+
import type { ComposerEnvironmentCandidate } from "@t3tools/client-runtime/composerThreadItems";
104+
import { offersLinkedEnvironments } from "@t3tools/client-runtime/link-request";
102105
import {
103106
ComposerDictationCancelAction,
104107
ComposerDictationDraftContent,
@@ -117,6 +120,7 @@ import {
117120

118121
export const COMPOSER_COLLAPSED_CHROME = 60;
119122

123+
const NO_MACHINES: ReadonlyArray<ComposerEnvironmentCandidate> = [];
120124
const COLLAPSED_EDITOR_DEFAULT_INSET = 6;
121125
// iOS puts line-height slack above glyphs. DM Sans's lowercase midline is
122126
// descender (0.31em) + half x-height (0.504em) above the line bottom.
@@ -523,11 +527,15 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
523527
return report !== null;
524528
};
525529

530+
const mentionableEnvironments = useMentionableEnvironments();
526531
const composerMenu = useComposerCommandMenu({
527532
draftMessage: draftMessage,
528533
ownerKey: composerDraftKey,
529534
environmentId: props.environmentId,
530535
threadShells: useThreadShells(),
536+
environments: offersLinkedEnvironments(props.serverConfig)
537+
? mentionableEnvironments
538+
: NO_MACHINES,
531539
currentThreadId: props.selectedThread.id,
532540
projectCwd: props.projectCwd,
533541
pullRequestProjectId: props.serverConfig?.environment.capabilities.pullRequests

‎apps/mobile/src/features/threads/use-composer-command-menu.ts‎

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,22 @@ import type {
77
ThreadId,
88
ThreadPullRequestLink,
99
} from "@t3tools/contracts";
10-
import { matchComposerThreadItems } from "@t3tools/client-runtime/composerThreadItems";
10+
import {
11+
type ComposerEnvironmentCandidate,
12+
matchComposerEnvironmentItems,
13+
matchComposerThreadItems,
14+
} from "@t3tools/client-runtime/composerThreadItems";
1115
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/models";
1216

1317
const EMPTY_THREAD_SHELLS: ReadonlyArray<EnvironmentThreadShell> = [];
18+
const EMPTY_ENVIRONMENTS: ReadonlyArray<ComposerEnvironmentCandidate> = [];
1419
import { COMPOSER_CONTEXT_MAX_RECORDS } from "@t3tools/contracts";
1520
import { formatComposerContextReference } from "@t3tools/shared/composerContextReferences";
16-
import { pullRequestComposerContext, threadComposerContext } from "../../lib/composerContext";
21+
import {
22+
environmentComposerContext,
23+
pullRequestComposerContext,
24+
threadComposerContext,
25+
} from "../../lib/composerContext";
1726
import { uuidv4 } from "../../lib/uuid";
1827
import {
1928
getComposerDraftSnapshot,
@@ -201,6 +210,7 @@ export function useComposerCommandMenu({
201210
ownerKey,
202211
environmentId,
203212
threadShells = EMPTY_THREAD_SHELLS,
213+
environments = EMPTY_ENVIRONMENTS,
204214
currentThreadId = null,
205215
projectCwd,
206216
pullRequestProjectId = null,
@@ -219,6 +229,7 @@ export function useComposerCommandMenu({
219229
readonly ownerKey: string | null;
220230
readonly environmentId: EnvironmentId | null;
221231
readonly threadShells?: ReadonlyArray<EnvironmentThreadShell>;
232+
readonly environments?: ReadonlyArray<ComposerEnvironmentCandidate>;
222233
readonly currentThreadId?: ThreadId | null;
223234
readonly projectCwd: string | null;
224235
readonly pullRequestProjectId?: ProjectId | null;
@@ -452,8 +463,12 @@ export function useComposerCommandMenu({
452463
now,
453464
})
454465
: [];
466+
const environmentItems = environmentId
467+
? matchComposerEnvironmentItems({ environments, environmentId, query: trigger.query })
468+
: [];
455469
return [
456470
...threadItems,
471+
...environmentItems,
457472
...pathSearch.entries.map((entry) => {
458473
const parts = entry.path.split("/");
459474
return {
@@ -473,6 +488,32 @@ export function useComposerCommandMenu({
473488

474489
const onSelect = (item: ComposerCommandItem) => {
475490
if (!trigger) return;
491+
if (item.type === "environment") {
492+
if (!ownerKey || trigger.kind !== "path") return;
493+
const record = environmentComposerContext(item.environmentId, item.label);
494+
const existing = getComposerDraftSnapshot(ownerKey).context?.records ?? [];
495+
const alreadyAttached = existing.some((entry) => entry.contextId === record.contextId);
496+
if (!alreadyAttached && existing.length >= COMPOSER_CONTEXT_MAX_RECORDS) {
497+
Dialog.alert("Too many context items", "Remove some context from the draft and try again.");
498+
return;
499+
}
500+
const result = replaceTextRange(
501+
draftMessage,
502+
trigger.rangeStart,
503+
trigger.rangeEnd,
504+
`${formatComposerContextReference(record)} `,
505+
);
506+
onChangeDraftMessage(result.text);
507+
if (!alreadyAttached) {
508+
const draft = getComposerDraftSnapshot(ownerKey);
509+
setComposerDraftContext(ownerKey, {
510+
version: 1,
511+
records: [...(draft.context?.records ?? []), record],
512+
});
513+
}
514+
setSelection({ start: result.cursor, end: result.cursor });
515+
return;
516+
}
476517
if (item.type === "thread") {
477518
if (!ownerKey || trigger.kind !== "path") return;
478519
const shell = threadShells.find(

0 commit comments

Comments
 (0)