Skip to content

Commit 2b63f76

Browse files
feat(web,mobile): @-mention a machine as a context chip
Typing @ and part of a machine's name in the composer now offers the user's other T3 Code environments beside threads and files, each with its machine icon. Picking one inserts a chip. The message carries only the machine's identity (environmentId and label, never an address), and the agent is told to link it with t3_environment_link if it is not linked yet, then pass the environmentId to delegate_task, t3_thread_launch and the other tools. Web keeps mentioned machines in the draft beside attached threads, persists them, restores them on undo and failed sends, and renders the chip in the composer and in sent messages. Mobile offers them in the @ popover and draws the chip natively. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 339c51c commit 2b63f76

29 files changed

Lines changed: 684 additions & 19 deletions

‎apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ContextChip.kt‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ class T3ContextChip(
160160
line(7f, 8f, 17f, 8f)
161161
line(7f, 12f, 14f, 12f)
162162
}
163+
// Two stacked rack units, each with a status light, like the SF Symbol iOS draws.
164+
"server.rack" -> {
165+
addRoundRect(3f, 3f, 21f, 11f, 2f, 2f, Path.Direction.CW)
166+
addRoundRect(3f, 13f, 21f, 21f, 2f, 2f, Path.Direction.CW)
167+
line(7f, 7f, 7.01f, 7f)
168+
line(7f, 17f, 7.01f, 17f)
169+
}
163170
"terminal", "play.rectangle", "photo" -> {
164171
addRoundRect(2f, 4f, 22f, 20f, 2f, 2f, Path.Direction.CW)
165172
when (symbol) {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,9 @@ export function ComposerContextSheet(props: {
313313
) : null}
314314
</View>
315315
) : null}
316+
{record.kind === "environment" ? (
317+
<ContextField label="Machine" value={record.label} />
318+
) : null}
316319
{record.kind === "skill" ? (
317320
<View className="gap-3">
318321
<ContextField label="Skill" value={record.name} />

‎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
export type ComposerCommandItem =
@@ -39,6 +42,14 @@ export type ComposerCommandItem =
3942
readonly label: string;
4043
readonly description: string;
4144
}
45+
| {
46+
readonly id: string;
47+
readonly type: "environment";
48+
readonly environmentId: EnvironmentId;
49+
readonly machine: EnvironmentMachineKind;
50+
readonly label: string;
51+
readonly description: string;
52+
}
4253
| {
4354
readonly id: string;
4455
readonly type: "slash-command";
@@ -109,6 +120,8 @@ function itemIcon(item: ComposerCommandItem): AppSymbolName | null {
109120
return null;
110121
case "thread":
111122
return "text.bubble";
123+
case "environment":
124+
return ENVIRONMENT_MACHINE_SYMBOLS[item.machine];
112125
}
113126
}
114127

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ import {
108108
waitForComposerDraftsLoaded,
109109
} from "../../state/use-composer-drafts";
110110
import { useEnvironmentServerConfig, useProjects, useThreadShells } from "../../state/entities";
111+
import { useMentionableEnvironments } from "../../state/environments";
111112
import { useProjectClone } from "../../state/projectClones";
112113
import { projectEnvironment } from "../../state/projects";
113114
import { sourceControlEnvironment } from "../../state/sourceControl";
@@ -484,6 +485,7 @@ export function NewTaskDraftScreen(props: {
484485
ownerKey: flow.draftKey,
485486
environmentId: selectedProject?.environmentId ?? null,
486487
threadShells: useThreadShells(),
488+
environments: useMentionableEnvironments(),
487489
pullRequestProjectId: selectedEnvironmentServerConfig?.environment.capabilities.pullRequests
488490
? (selectedProject?.id ?? null)
489491
: null,

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

Lines changed: 4 additions & 1 deletion
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";
@@ -440,9 +441,11 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
440441

441442
const composerMenu = useComposerCommandMenu({
442443
draftMessage: props.draftMessage,
443-
ownerKey: composerOwnerKey,
444+
// A queued edit has its own draft: its chips belong with the edited text.
445+
ownerKey: composerDraftKey,
444446
environmentId: props.environmentId,
445447
threadShells: useThreadShells(),
448+
environments: useMentionableEnvironments(),
446449
currentThreadId: props.selectedThread.id,
447450
projectCwd: props.projectCwd,
448451
pullRequestProjectId: props.serverConfig?.environment.capabilities.pullRequests

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

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,25 @@ 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 {
1520
COMPOSER_CONTEXT_MAX_RECORDS,
1621
PROVIDER_WORKSPACE_SNAPSHOT_TTL_MS,
1722
} from "@t3tools/contracts";
1823
import { formatComposerContextReference } from "@t3tools/shared/composerContextReferences";
19-
import { pullRequestComposerContext, threadComposerContext } from "../../lib/composerContext";
24+
import {
25+
environmentComposerContext,
26+
pullRequestComposerContext,
27+
threadComposerContext,
28+
} from "../../lib/composerContext";
2029
import { uuidv4 } from "../../lib/uuid";
2130
import {
2231
getComposerDraftSnapshot,
@@ -172,6 +181,7 @@ export function useComposerCommandMenu({
172181
ownerKey,
173182
environmentId,
174183
threadShells = EMPTY_THREAD_SHELLS,
184+
environments = EMPTY_ENVIRONMENTS,
175185
currentThreadId = null,
176186
projectCwd,
177187
pullRequestProjectId = null,
@@ -190,6 +200,7 @@ export function useComposerCommandMenu({
190200
readonly ownerKey: string | null;
191201
readonly environmentId: EnvironmentId | null;
192202
readonly threadShells?: ReadonlyArray<EnvironmentThreadShell>;
203+
readonly environments?: ReadonlyArray<ComposerEnvironmentCandidate>;
193204
readonly currentThreadId?: ThreadId | null;
194205
readonly projectCwd: string | null;
195206
readonly pullRequestProjectId?: ProjectId | null;
@@ -504,8 +515,12 @@ export function useComposerCommandMenu({
504515
query: trigger.query,
505516
})
506517
: [];
518+
const environmentItems = environmentId
519+
? matchComposerEnvironmentItems({ environments, environmentId, query: trigger.query })
520+
: [];
507521
return [
508522
...threadItems,
523+
...environmentItems,
509524
...pathSearch.entries.map((entry) => {
510525
const parts = entry.path.split("/");
511526
return {
@@ -525,6 +540,7 @@ export function useComposerCommandMenu({
525540
currentThreadId,
526541
environmentId,
527542
threadShells,
543+
environments,
528544
hasThread,
529545
hasCompactableConversation,
530546
onUpdateInteractionMode,
@@ -575,6 +591,35 @@ export function useComposerCommandMenu({
575591
setSelection({ start: result.cursor, end: result.cursor });
576592
return;
577593
}
594+
if (item.type === "environment") {
595+
if (!ownerKey || trigger.kind !== "path") return;
596+
const record = environmentComposerContext(item.environmentId, item.label);
597+
const existing = getComposerDraftSnapshot(ownerKey).context?.records ?? [];
598+
const alreadyAttached = existing.some((entry) => entry.contextId === record.contextId);
599+
if (!alreadyAttached && existing.length >= COMPOSER_CONTEXT_MAX_RECORDS) {
600+
Dialog.alert(
601+
"Too many context items",
602+
"Remove some context from the draft and try again.",
603+
);
604+
return;
605+
}
606+
const result = replaceTextRange(
607+
draftMessage,
608+
trigger.rangeStart,
609+
trigger.rangeEnd,
610+
`${formatComposerContextReference(record)} `,
611+
);
612+
onChangeDraftMessage(result.text);
613+
if (!alreadyAttached) {
614+
const draft = getComposerDraftSnapshot(ownerKey);
615+
setComposerDraftContext(ownerKey, {
616+
version: 1,
617+
records: [...(draft.context?.records ?? []), record],
618+
});
619+
}
620+
setSelection({ start: result.cursor, end: result.cursor });
621+
return;
622+
}
578623
if (item.type === "pull-request") {
579624
if (
580625
!ownerKey ||

‎apps/mobile/src/lib/composerChipPresentation.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ describe("composerChipSizeSuffix", () => {
1717
});
1818

1919
describe("contextChipPresentation image detection", () => {
20+
it("draws a mentioned machine as a machine, not the generic file chip", async () => {
21+
const { contextChipPresentation } = await import("./composerChipPresentation");
22+
expect(contextChipPresentation("environment")).toEqual({
23+
accent: "#3f9a4f",
24+
symbol: "server.rack",
25+
});
26+
});
27+
2028
it("treats a picture attached through the file picker as an image", async () => {
2129
const { contextChipPresentation } = await import("./composerChipPresentation");
2230
expect(

‎apps/mobile/src/lib/composerChipPresentation.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const CONTEXT_CHIP_PRESENTATIONS = {
1616
"review-comment": { accent: "#8a70dd", symbol: "text.bubble" },
1717
"pull-request": { accent: "#7079e4", symbol: "git-pull-request" },
1818
skill: { accent: "#b261be", symbol: "cube" },
19+
// A machine: the record carries only its identity, so every machine wears one glyph.
20+
environment: { accent: "#3f9a4f", symbol: "server.rack" },
1921
} as const;
2022

2123
export function composerChipSizeSuffix(record?: {

‎apps/mobile/src/lib/composerContext.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
type ReviewCommentContextRecord,
1212
type ScopedThreadRef,
1313
type ThreadContextRecord,
14+
type EnvironmentContextRecord,
15+
type EnvironmentId,
1416
} from "@t3tools/contracts";
1517
import * as Schema from "effect/Schema";
1618
import {
@@ -112,6 +114,20 @@ export function threadComposerContext(ref: ScopedThreadRef, title: string): Thre
112114
};
113115
}
114116

117+
/** Same identity as web: one record per machine, so mentioning it again reuses the chip. */
118+
export function environmentComposerContext(
119+
environmentId: EnvironmentId,
120+
label: string,
121+
): EnvironmentContextRecord {
122+
return {
123+
version: 1,
124+
kind: "environment",
125+
contextId: ComposerContextId.make(`environment_${environmentId}`),
126+
label: sanitizeComposerContextLabel(label, "environment"),
127+
environmentId,
128+
};
129+
}
130+
115131
export function pullRequestComposerContext(
116132
pullRequest: PullRequestContextMetadata,
117133
id: string,

‎apps/mobile/src/state/environments.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import {
44
hasRelayRoute,
55
type EnvironmentPresentation as BaseEnvironmentPresentation,
66
} from "@t3tools/client-runtime/connection";
7-
import type { EnvironmentId } from "@t3tools/contracts";
7+
import type { ComposerEnvironmentCandidate } from "@t3tools/client-runtime/composerThreadItems";
8+
import { type EnvironmentId, resolveEnvironmentMachineKind } from "@t3tools/contracts";
89
import { useMemo } from "react";
910

1011
import { environmentCatalog } from "../connection/catalog";
@@ -55,3 +56,17 @@ export function useEnvironments() {
5556
export function useEnvironmentConnectionState(environmentId: EnvironmentId) {
5657
return useEnvironmentQuery(environmentCatalog.stateAtom(environmentId));
5758
}
59+
60+
/** The user's machines as `@` mention candidates, drawn with their machine kind. */
61+
export function useMentionableEnvironments(): ReadonlyArray<ComposerEnvironmentCandidate> {
62+
const { environments } = useEnvironments();
63+
return useMemo(
64+
() =>
65+
environments.map((environment) => ({
66+
environmentId: environment.environmentId,
67+
label: environment.label,
68+
machine: resolveEnvironmentMachineKind(environment.serverConfig),
69+
})),
70+
[environments],
71+
);
72+
}

0 commit comments

Comments
 (0)