Skip to content

Commit c7713b9

Browse files
feat: attach Linear issues as context in the composer
The composer's attach button now asks what to attach: files and images, or a Linear issue. A searchable picker lists your open assigned issues, searches as you type, and looks up ENG-123 or an issue link directly. The same picker opens from the command palette, and the `#` menu shows Linear issues beside pull requests (`#ENG-123` ranks the issue first; a bare number stays a pull request). An attached issue becomes a `linear-issue` context chip holding a markdown snapshot taken when it was attached, which is inlined into the prompt for every provider. Chips show the snapshot in the composer and in sent messages. Mobile gets the same: a Linear action in the attach menu with a picker sheet, chip details, and a Settings > Linear screen with the paste-back login. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent d2f80ef commit c7713b9

36 files changed

Lines changed: 1324 additions & 36 deletions

‎apps/mobile/modules/t3-markdown-text/src/nativeMarkdownText.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const CONTEXT_CHIP_PRESENTATIONS = {
1818
"review-comment": { accent: "#8a70dd", symbol: "text.bubble" },
1919
"pull-request": { accent: "#7079e4", symbol: "git-pull-request" },
2020
skill: { accent: "#b261be", symbol: "cube" },
21+
"linear-issue": { accent: "#617de6", symbol: "ticket" },
2122
} as const;
2223

2324
/**

‎apps/mobile/src/Stack.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ import {
8080
SettingsEnvironmentSourceControlRouteScreen,
8181
} from "./features/settings/SettingsServerControlsRouteScreen";
8282
import { SettingsKeyboardRouteScreen } from "./features/settings/SettingsKeyboardRouteScreen";
83+
import { SettingsLinearRouteScreen } from "./features/settings/SettingsLinearRouteScreen";
8384
import { SettingsLegalRouteScreen } from "./features/settings/SettingsLegalRouteScreen";
8485
import {
8586
SettingsOpenSourceLicenseRouteScreen,
@@ -219,6 +220,11 @@ const SettingsContentStack = createNativeStackNavigator({
219220
linking: "maintenance",
220221
options: { title: "Maintenance" },
221222
}),
223+
SettingsLinear: createNativeStackScreen({
224+
screen: SettingsLinearRouteScreen,
225+
linking: "linear",
226+
options: { title: "Linear" },
227+
}),
222228
SettingsNotifications: createNativeStackScreen({
223229
screen: SettingsNotificationsRouteScreen,
224230
linking: "notifications",

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,33 @@ import { useAndroidControlSizing } from "./useAndroidControlSizing";
55
import { SymbolView } from "./AppSymbol";
66
import { ControlPillMenu } from "./ControlPill";
77

8-
const ATTACHMENT_MENU_ACTIONS: MenuAction[] = [
9-
{ id: "photos", title: "Photo Library", image: "photo" },
10-
{ id: "files", title: "Choose Files", image: "folder" },
11-
];
8+
const PHOTOS_ACTION: MenuAction = { id: "photos", title: "Photo Library", image: "photo" };
9+
const FILES_ACTION: MenuAction = { id: "files", title: "Choose Files", image: "folder" };
10+
const LINEAR_ACTION: MenuAction = { id: "linear", title: "Linear issue", image: "ticket" };
1211

1312
export function ComposerAttachmentButton(props: {
1413
readonly disabled?: boolean;
1514
readonly supportsFiles: boolean;
1615
readonly onPickMedia: () => Promise<void>;
1716
readonly onPickFiles: () => Promise<void>;
17+
/** Omit to hide the Linear action. See `useLinearIssuePicker`. */
18+
readonly onPickLinearIssue?: () => void;
1819
}) {
1920
const { scale } = useAndroidControlSizing();
21+
const actions = [
22+
PHOTOS_ACTION,
23+
...(props.supportsFiles ? [FILES_ACTION] : []),
24+
...(props.onPickLinearIssue ? [LINEAR_ACTION] : []),
25+
];
26+
const usesMenu = !props.disabled && actions.length > 1;
2027
const button = (
2128
<Pressable
2229
accessibilityLabel="Add attachment"
2330
accessibilityRole="button"
2431
accessibilityState={{ disabled: props.disabled }}
2532
className="size-[44px] shrink-0 items-center justify-center rounded-full active:opacity-70 disabled:opacity-50"
2633
disabled={props.disabled}
27-
onPress={props.supportsFiles ? undefined : () => void props.onPickMedia()}
34+
onPress={usesMenu ? undefined : () => void props.onPickMedia()}
2835
>
2936
<SymbolView
3037
name="plus"
@@ -36,7 +43,7 @@ export function ComposerAttachmentButton(props: {
3643
</Pressable>
3744
);
3845

39-
if (props.disabled || !props.supportsFiles) {
46+
if (!usesMenu) {
4047
return button;
4148
}
4249

@@ -45,12 +52,14 @@ export function ComposerAttachmentButton(props: {
4552
accessible
4653
accessibilityLabel="Add attachment"
4754
accessibilityRole="button"
48-
actions={ATTACHMENT_MENU_ACTIONS}
55+
actions={actions}
4956
onPressAction={({ nativeEvent }) => {
5057
if (nativeEvent.event === "photos") {
5158
void props.onPickMedia();
5259
} else if (nativeEvent.event === "files") {
5360
void props.onPickFiles();
61+
} else if (nativeEvent.event === "linear") {
62+
props.onPickLinearIssue?.();
5463
}
5564
}}
5665
>

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
isFileBackedComposerAttachment,
2727
type DraftComposerAttachment,
2828
} from "../lib/composerImages";
29+
import { tryOpenExternalUrl } from "../lib/openExternalUrl";
2930
import { FilePreviewModal } from "./FilePreviewModal";
3031
import { VideoPreviewModal } from "./VideoPreviewModal";
3132
import { ComposerContextAttachment } from "./ComposerContextAttachment";
@@ -339,6 +340,35 @@ export function ComposerContextSheet(props: {
339340
<ContextField label="Styles" value={record.styles} code />
340341
</>
341342
) : null}
343+
{record.kind === "linear-issue" ? (
344+
<View className="gap-3">
345+
<View className="gap-1">
346+
<Text selectable className="text-lg font-t3-semibold text-foreground">
347+
{record.title}
348+
</Text>
349+
<Text className="text-sm text-foreground-muted">
350+
{record.identifier} · {record.stateName}
351+
</Text>
352+
</View>
353+
{/^https?:\/\//i.test(record.url) ? (
354+
<Pressable
355+
accessibilityRole="link"
356+
onPress={() => {
357+
void tryOpenExternalUrl(record.url, "linear").then((opened) => {
358+
if (!opened) Alert.alert("Could not open Linear", "Try again later.");
359+
});
360+
}}
361+
className="rounded-xl bg-subtle p-4"
362+
>
363+
<Text className="text-foreground">Open in Linear</Text>
364+
</Pressable>
365+
) : null}
366+
{/* Plain text like the other captured context here: exactly what the agent received. */}
367+
<Text selectable className="text-sm text-foreground">
368+
{record.markdown}
369+
</Text>
370+
</View>
371+
) : null}
342372
{record.kind === "image" ? (
343373
<ContextField
344374
label="File"
Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
import type { EnvironmentId, LinearIssueSummary } from "@t3tools/contracts";
2+
import { useAtomValue } from "@effect/atom-react";
3+
import { linearIssueContextRecord } from "@t3tools/client-runtime/state/linear";
4+
import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
5+
import { formatComposerContextReference } from "@t3tools/shared/composerContextReferences";
6+
import * as Cause from "effect/Cause";
7+
import * as Option from "effect/Option";
8+
import { AsyncResult } from "effect/unstable/reactivity";
9+
import { useNavigation } from "@react-navigation/native";
10+
import { useState, type ReactNode } from "react";
11+
import { ActivityIndicator, Alert, FlatList, Modal, Platform, Pressable, View } from "react-native";
12+
import { useSafeAreaInsets } from "react-native-safe-area-context";
13+
14+
import { linearEnvironment } from "../state/linear";
15+
import { useDebouncedValue } from "../state/queries";
16+
import { useEnvironmentQuery } from "../state/query";
17+
import { useAtomCommand } from "../state/use-atom-command";
18+
import {
19+
captureComposerDraftInsertion,
20+
insertComposerDraftContext,
21+
type ComposerDraftInsertion,
22+
} from "../state/use-composer-drafts";
23+
import { AppText as Text, AppTextInput } from "./AppText";
24+
25+
/** Linear allows 30 searches a minute, so typing settles before it queries. */
26+
const SEARCH_DEBOUNCE_MS = 300;
27+
28+
/** Linear's failures carry a reason; a rate limit deserves a clearer hint than its detail. */
29+
function linearErrorMessage(error: unknown, fallback: string): string {
30+
if (typeof error === "object" && error !== null && "reason" in error) {
31+
if (error.reason === "rate-limited") return "Linear is busy. Try again shortly.";
32+
if (error.reason === "not-connected" || error.reason === "revoked") {
33+
return "Linear is not connected. Connect it in Settings.";
34+
}
35+
}
36+
return error instanceof Error && error.message.trim() ? error.message : fallback;
37+
}
38+
39+
/**
40+
* The composer's Linear action. The owner renders `sheet` somewhere that outlives composer
41+
* focus: opening the sheet blurs the editor, which can unmount a focus-dependent toolbar.
42+
*/
43+
export function useLinearIssuePicker(
44+
target: { readonly environmentId: EnvironmentId; readonly draftKey: string } | null,
45+
): { readonly open: () => void; readonly sheet: ReactNode } {
46+
const navigation = useNavigation();
47+
const connection = useEnvironmentQuery(
48+
target
49+
? linearEnvironment.connection({ environmentId: target.environmentId, input: {} })
50+
: null,
51+
);
52+
const [opened, setOpened] = useState<{
53+
readonly environmentId: EnvironmentId;
54+
readonly draftKey: string;
55+
readonly insertion: ComposerDraftInsertion;
56+
} | null>(null);
57+
const open = () => {
58+
if (!target) return;
59+
// Connecting is a settings task; the picker only attaches.
60+
if (connection.data && connection.data.phase !== "connected") {
61+
navigation.navigate("SettingsSheet", {
62+
screen: "SettingsContent",
63+
params: { screen: "SettingsLinear" },
64+
});
65+
return;
66+
}
67+
setOpened({ ...target, insertion: captureComposerDraftInsertion(target.draftKey) });
68+
};
69+
return {
70+
open,
71+
sheet: opened ? <LinearIssuePickerSheet {...opened} onClose={() => setOpened(null)} /> : null,
72+
};
73+
}
74+
75+
/** Attaches a Linear issue at the caret the composer had when the sheet opened. */
76+
function LinearIssuePickerSheet(props: {
77+
readonly environmentId: EnvironmentId;
78+
readonly draftKey: string;
79+
readonly insertion: ComposerDraftInsertion;
80+
readonly onClose: () => void;
81+
}) {
82+
const insets = useSafeAreaInsets();
83+
const connection = useEnvironmentQuery(
84+
linearEnvironment.connection({ environmentId: props.environmentId, input: {} }),
85+
);
86+
const phase = connection.data?.phase;
87+
return (
88+
<Modal presentationStyle="pageSheet" animationType="slide" onRequestClose={props.onClose}>
89+
<View
90+
className="flex-1 bg-sheet-solid"
91+
style={
92+
Platform.OS === "android"
93+
? { paddingTop: insets.top, paddingBottom: insets.bottom }
94+
: undefined
95+
}
96+
>
97+
<View className="flex-row items-center justify-between p-4">
98+
<Text className="text-lg text-foreground">Linear issue</Text>
99+
<Pressable accessibilityRole="button" onPress={props.onClose} className="p-3">
100+
<Text className="text-foreground">Cancel</Text>
101+
</Pressable>
102+
</View>
103+
{phase === "connected" ? (
104+
<LinearIssueSearch {...props} />
105+
) : (
106+
<View className="flex-1 items-center justify-center p-6">
107+
{phase === undefined && !connection.error ? (
108+
<ActivityIndicator />
109+
) : (
110+
<Text className="text-center text-foreground-muted">
111+
{connection.error ?? "Linear is not connected. Connect it in Settings > Linear."}
112+
</Text>
113+
)}
114+
</View>
115+
)}
116+
</View>
117+
</Modal>
118+
);
119+
}
120+
121+
function LinearIssueSearch(props: {
122+
readonly environmentId: EnvironmentId;
123+
readonly draftKey: string;
124+
readonly insertion: ComposerDraftInsertion;
125+
readonly onClose: () => void;
126+
}) {
127+
const insets = useSafeAreaInsets();
128+
const [query, setQuery] = useState("");
129+
const trimmed = query.trim();
130+
const settled = useDebouncedValue(trimmed, SEARCH_DEBOUNCE_MS);
131+
// An empty query lists the viewer's open assigned issues.
132+
const result = useAtomValue(
133+
linearEnvironment.issues({
134+
environmentId: props.environmentId,
135+
input: settled ? { query: settled } : {},
136+
}),
137+
);
138+
const getIssue = useAtomCommand(linearEnvironment.getIssue, {
139+
label: "linear issue fetch",
140+
reportFailure: false,
141+
});
142+
const [attaching, setAttaching] = useState<string | null>(null);
143+
const issues = Option.getOrNull(AsyncResult.value(result))?.issues ?? [];
144+
const pending = settled !== trimmed || result.waiting;
145+
const error =
146+
result._tag === "Failure"
147+
? linearErrorMessage(Cause.squash(result.cause), "Could not load Linear issues.")
148+
: null;
149+
150+
const attach = async (issue: LinearIssueSummary) => {
151+
if (attaching) return;
152+
setAttaching(issue.id);
153+
try {
154+
const fetched = await getIssue({
155+
environmentId: props.environmentId,
156+
input: { id: issue.id },
157+
});
158+
if (fetched._tag === "Failure") {
159+
Alert.alert(
160+
"Could not attach issue",
161+
linearErrorMessage(squashAtomCommandFailure(fetched), "Try again."),
162+
);
163+
return;
164+
}
165+
const record = linearIssueContextRecord(fetched.value);
166+
if (
167+
!insertComposerDraftContext(
168+
props.draftKey,
169+
{
170+
text: formatComposerContextReference(record),
171+
context: { version: 1, records: [record] },
172+
},
173+
props.insertion,
174+
)
175+
) {
176+
Alert.alert("Too many context items", "Remove some context from the draft and try again.");
177+
return;
178+
}
179+
props.onClose();
180+
} finally {
181+
setAttaching(null);
182+
}
183+
};
184+
185+
return (
186+
<View className="flex-1">
187+
<View className="px-4 pb-3">
188+
<AppTextInput
189+
accessibilityLabel="Search Linear issues"
190+
autoFocus
191+
autoCapitalize="none"
192+
autoCorrect={false}
193+
clearButtonMode="while-editing"
194+
placeholder="Search, or paste ENG-123 or an issue link"
195+
returnKeyType="search"
196+
value={query}
197+
onChangeText={setQuery}
198+
/>
199+
</View>
200+
<FlatList
201+
data={issues}
202+
keyExtractor={(issue) => issue.id}
203+
keyboardShouldPersistTaps="handled"
204+
contentContainerStyle={{ paddingBottom: Math.max(insets.bottom, 16) }}
205+
ListHeaderComponent={
206+
!trimmed && issues.length > 0 ? (
207+
<Text className="px-4 pb-2 text-sm text-foreground-muted">Assigned to you</Text>
208+
) : null
209+
}
210+
ListEmptyComponent={
211+
<View className="items-center p-6">
212+
{pending ? (
213+
<ActivityIndicator />
214+
) : (
215+
<Text
216+
selectable={error !== null}
217+
className={
218+
error ? "text-center text-danger-foreground" : "text-center text-foreground-muted"
219+
}
220+
>
221+
{error ?? (trimmed ? "No matching issues." : "No open issues are assigned to you.")}
222+
</Text>
223+
)}
224+
</View>
225+
}
226+
renderItem={({ item }) => (
227+
<Pressable
228+
accessibilityRole="button"
229+
accessibilityLabel={`${item.identifier} ${item.title}, ${item.stateName}`}
230+
disabled={attaching !== null}
231+
onPress={() => void attach(item)}
232+
className="flex-row items-center gap-3 px-4 py-3 active:bg-subtle disabled:opacity-60"
233+
>
234+
<View className="min-w-0 flex-1 gap-0.5">
235+
<Text className="text-base text-foreground" numberOfLines={2}>
236+
{item.title}
237+
</Text>
238+
<Text className="text-sm text-foreground-muted" numberOfLines={1}>
239+
{item.identifier} · {item.stateName}
240+
</Text>
241+
</View>
242+
{attaching === item.id ? <ActivityIndicator /> : null}
243+
</Pressable>
244+
)}
245+
/>
246+
</View>
247+
);
248+
}

0 commit comments

Comments
 (0)