Skip to content

Commit 4da14ba

Browse files
feat(mobile): start from a PR or issue, hand off to another model, and attach repositories (#107)
Mobile now has the fork's main workflow entry points that were web and desktop only: - A new thread's ⋯ button starts from a pull request (checked out in its own worktree) or a Linear issue (attached, then linked once the draft sends), offering an existing thread first. - A started chat's Hand off menu forks it into a new tab on any provider's model, carrying a summary of the chat and the unsent draft. - The composer's attach menu picks a repository to clone into the workspace's context folder. The pull request "in use" check and the repository picker's ranking move to client-runtime so web and mobile share them. Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
1 parent c1b3a6b commit 4da14ba

23 files changed

Lines changed: 995 additions & 167 deletions

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import { ControlPillMenu } from "./ControlPill";
88
const PHOTOS_ACTION: MenuAction = { id: "photos", title: "Photo Library", image: "photo" };
99
const FILES_ACTION: MenuAction = { id: "files", title: "Choose Files", image: "folder" };
1010
const LINEAR_ACTION: MenuAction = { id: "linear", title: "Linear issue", image: "ticket" };
11+
const REPOSITORY_ACTION: MenuAction = {
12+
id: "repository",
13+
title: "Repository",
14+
image: "arrow.triangle.branch",
15+
};
1116

1217
export function ComposerAttachmentButton(props: {
1318
readonly disabled?: boolean;
@@ -16,12 +21,15 @@ export function ComposerAttachmentButton(props: {
1621
readonly onPickFiles: () => Promise<void>;
1722
/** Omit to hide the Linear action. See `useLinearIssuePicker`. */
1823
readonly onPickLinearIssue?: () => void;
24+
/** Omit to hide the repository action. See `useRepositoryPicker`. */
25+
readonly onPickRepository?: () => void;
1926
}) {
2027
const { scale } = useAndroidControlSizing();
2128
const actions = [
2229
PHOTOS_ACTION,
2330
...(props.supportsFiles ? [FILES_ACTION] : []),
2431
...(props.onPickLinearIssue ? [LINEAR_ACTION] : []),
32+
...(props.onPickRepository ? [REPOSITORY_ACTION] : []),
2533
];
2634
const usesMenu = !props.disabled && actions.length > 1;
2735
const button = (
@@ -60,6 +68,8 @@ export function ComposerAttachmentButton(props: {
6068
void props.onPickFiles();
6169
} else if (nativeEvent.event === "linear") {
6270
props.onPickLinearIssue?.();
71+
} else if (nativeEvent.event === "repository") {
72+
props.onPickRepository?.();
6373
}
6474
}}
6575
>

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,13 @@ export function ComposerContextSheet(props: {
373373
</Text>
374374
</View>
375375
) : null}
376+
{record.kind === "thread-tab" ? (
377+
<View className="gap-3">
378+
<ContextField label="Chat" value={record.title} />
379+
{/* Exactly what the agent receives in place of the other chat. */}
380+
<ContextField label="Summary" value={record.summary} />
381+
</View>
382+
) : null}
376383
{record.kind === "repository" ? (
377384
<View className="gap-3">
378385
<ContextField label="Repository" value={record.nameWithOwner} />

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

Lines changed: 104 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
1-
import type { EnvironmentId, LinearIssueSummary, ThreadId } from "@t3tools/contracts";
1+
import type {
2+
EnvironmentId,
3+
LinearIssueSummary,
4+
OrchestrationMessageContext,
5+
ProjectId,
6+
ThreadId,
7+
} from "@t3tools/contracts";
28
import { useAtomValue } from "@effect/atom-react";
3-
import { linearIssueContextRecord } from "@t3tools/client-runtime/state/linear";
9+
import {
10+
linearIssueContextRecord,
11+
threadsForLinearIssue,
12+
} from "@t3tools/client-runtime/state/linear";
413
import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
514
import { formatComposerContextReference } from "@t3tools/shared/composerContextReferences";
615
import * as Cause from "effect/Cause";
716
import * as Option from "effect/Option";
817
import { AsyncResult } from "effect/unstable/reactivity";
9-
import { useNavigation } from "@react-navigation/native";
18+
import { StackActions, useNavigation } from "@react-navigation/native";
1019
import { useState, type ReactNode } from "react";
11-
import { ActivityIndicator, Alert, FlatList, Modal, Platform, Pressable, View } from "react-native";
20+
import { ActivityIndicator, Alert, FlatList, Pressable, View } from "react-native";
1221
import { useSafeAreaInsets } from "react-native-safe-area-context";
1322

23+
import { useThreadShells } from "../state/entities";
1424
import { linearEnvironment } from "../state/linear";
1525
import { useDebouncedValue } from "../state/queries";
1626
import { useEnvironmentQuery } from "../state/query";
@@ -20,7 +30,9 @@ import {
2030
insertComposerDraftContext,
2131
type ComposerDraftInsertion,
2232
} from "../state/use-composer-drafts";
33+
import { confirmOpenExistingThread } from "./confirmOpenExistingThread";
2334
import { AppText as Text, AppTextInput } from "./AppText";
35+
import { PickerSheet } from "./PickerSheet";
2436

2537
/** Linear allows 30 searches a minute, so typing settles before it queries. */
2638
const SEARCH_DEBOUNCE_MS = 300;
@@ -36,12 +48,17 @@ function linearErrorMessage(error: unknown, fallback: string): string {
3648
return error instanceof Error && error.message.trim() ? error.message : fallback;
3749
}
3850

39-
/** Attach inserts the issue into a composer draft; link links it to the thread's tab group. */
51+
/**
52+
* Attach inserts the issue into a composer draft; link links it to the thread's tab group. An
53+
* attach with `startFrom` starts a new thread from the issue: it first offers threads already
54+
* linked to it, and the thread the draft creates is linked once it sends.
55+
*/
4056
export type LinearIssuePickerTarget =
4157
| {
4258
readonly mode?: "attach";
4359
readonly environmentId: EnvironmentId;
4460
readonly draftKey: string;
61+
readonly startFrom?: { readonly projectId: ProjectId };
4562
}
4663
| {
4764
readonly mode: "link";
@@ -54,10 +71,31 @@ type OpenedLinearIssuePicker =
5471
readonly mode: "attach";
5572
readonly environmentId: EnvironmentId;
5673
readonly draftKey: string;
74+
readonly startFrom?: { readonly projectId: ProjectId };
5775
readonly insertion: ComposerDraftInsertion;
5876
}
5977
| { readonly mode: "link"; readonly environmentId: EnvironmentId; readonly threadId: ThreadId };
6078

79+
/** Issues picked to start a draft's thread from, by draft key, until the draft sends. */
80+
const startFromIssueIds = new Map<string, string>();
81+
82+
/**
83+
* The issue the draft was started from, if its chip is still in the draft. Clears it: the caller
84+
* links the thread the draft just created.
85+
*/
86+
export function takeStartFromLinearIssue(
87+
draftKey: string,
88+
context: OrchestrationMessageContext | undefined,
89+
): string | null {
90+
const issueId = startFromIssueIds.get(draftKey);
91+
startFromIssueIds.delete(draftKey);
92+
if (issueId === undefined) return null;
93+
const attached = context?.records.some(
94+
(record) => record.kind === "linear-issue" && "issueId" in record && record.issueId === issueId,
95+
);
96+
return attached ? issueId : null;
97+
}
98+
6199
/**
62100
* A Linear issue picker. The owner renders `sheet` somewhere that outlives composer focus:
63101
* opening the sheet blurs the editor, which can unmount a focus-dependent toolbar.
@@ -104,49 +142,48 @@ export function useLinearIssuePicker(target: LinearIssuePickerTarget | null): {
104142
* the thread's tab group.
105143
*/
106144
function LinearIssuePickerSheet(props: OpenedLinearIssuePicker & { readonly onClose: () => void }) {
107-
const insets = useSafeAreaInsets();
108145
const connection = useEnvironmentQuery(
109146
linearEnvironment.connection({ environmentId: props.environmentId, input: {} }),
110147
);
111148
const phase = connection.data?.phase;
112149
return (
113-
<Modal presentationStyle="pageSheet" animationType="slide" onRequestClose={props.onClose}>
114-
<View
115-
className="flex-1 bg-sheet-solid"
116-
style={
117-
Platform.OS === "android"
118-
? { paddingTop: insets.top, paddingBottom: insets.bottom }
119-
: undefined
120-
}
121-
>
122-
<View className="flex-row items-center justify-between p-4">
123-
<Text className="text-lg text-foreground">
124-
{props.mode === "link" ? "Link Linear issue" : "Linear issue"}
125-
</Text>
126-
<Pressable accessibilityRole="button" onPress={props.onClose} className="p-3">
127-
<Text className="text-foreground">Cancel</Text>
128-
</Pressable>
150+
<PickerSheet
151+
title={
152+
props.mode === "link"
153+
? "Link Linear issue"
154+
: props.startFrom
155+
? "Start from issue"
156+
: "Linear issue"
157+
}
158+
onClose={props.onClose}
159+
>
160+
{phase === "connected" ? (
161+
<LinearIssueSearch {...props} />
162+
) : (
163+
<View className="flex-1 items-center justify-center p-6">
164+
{phase === undefined && !connection.error ? (
165+
<ActivityIndicator />
166+
) : (
167+
<Text className="text-center text-foreground-muted">
168+
{connection.error ?? "Linear is not connected. Connect it in Settings > Linear."}
169+
</Text>
170+
)}
129171
</View>
130-
{phase === "connected" ? (
131-
<LinearIssueSearch {...props} />
132-
) : (
133-
<View className="flex-1 items-center justify-center p-6">
134-
{phase === undefined && !connection.error ? (
135-
<ActivityIndicator />
136-
) : (
137-
<Text className="text-center text-foreground-muted">
138-
{connection.error ?? "Linear is not connected. Connect it in Settings > Linear."}
139-
</Text>
140-
)}
141-
</View>
142-
)}
143-
</View>
144-
</Modal>
172+
)}
173+
</PickerSheet>
145174
);
146175
}
147176

148177
function LinearIssueSearch(props: OpenedLinearIssuePicker & { readonly onClose: () => void }) {
149178
const insets = useSafeAreaInsets();
179+
const navigation = useNavigation();
180+
const startFrom = props.mode === "attach" ? props.startFrom : undefined;
181+
const threadShells = useThreadShells();
182+
const threadLinks = useEnvironmentQuery(
183+
startFrom
184+
? linearEnvironment.threadLinks({ environmentId: props.environmentId, input: {} })
185+
: null,
186+
).data;
150187
const [query, setQuery] = useState("");
151188
const trimmed = query.trim();
152189
const settled = useDebouncedValue(trimmed, SEARCH_DEBOUNCE_MS);
@@ -173,8 +210,35 @@ function LinearIssueSearch(props: OpenedLinearIssuePicker & { readonly onClose:
173210
? linearErrorMessage(Cause.squash(result.cause), "Could not load Linear issues.")
174211
: null;
175212

176-
const attach = async (issue: LinearIssueSummary) => {
213+
const pick = async (issue: LinearIssueSummary) => {
177214
if (attaching) return;
215+
if (startFrom) {
216+
const existing = threadsForLinearIssue(
217+
threadShells.filter(
218+
(thread) =>
219+
thread.environmentId === props.environmentId &&
220+
thread.projectId === startFrom.projectId,
221+
),
222+
threadLinks,
223+
issue.id,
224+
);
225+
const choice = await confirmOpenExistingThread(issue.identifier, existing);
226+
if (choice === "cancel") return;
227+
if (choice !== "start") {
228+
props.onClose();
229+
navigation.dispatch(
230+
StackActions.replace("Thread", {
231+
environmentId: String(choice.environmentId),
232+
threadId: String(choice.id),
233+
}),
234+
);
235+
return;
236+
}
237+
}
238+
await attach(issue);
239+
};
240+
241+
const attach = async (issue: LinearIssueSummary) => {
178242
setAttaching(issue.id);
179243
try {
180244
if (props.mode === "link") {
@@ -217,6 +281,7 @@ function LinearIssueSearch(props: OpenedLinearIssuePicker & { readonly onClose:
217281
Alert.alert("Too many context items", "Remove some context from the draft and try again.");
218282
return;
219283
}
284+
if (startFrom) startFromIssueIds.set(props.draftKey, issue.id);
220285
props.onClose();
221286
} finally {
222287
setAttaching(null);
@@ -269,7 +334,7 @@ function LinearIssueSearch(props: OpenedLinearIssuePicker & { readonly onClose:
269334
accessibilityRole="button"
270335
accessibilityLabel={`${item.identifier} ${item.title}, ${item.stateName}`}
271336
disabled={attaching !== null}
272-
onPress={() => void attach(item)}
337+
onPress={() => void pick(item)}
273338
className="flex-row items-center gap-3 px-4 py-3 active:bg-subtle disabled:opacity-60"
274339
>
275340
<View className="min-w-0 flex-1 gap-0.5">
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type { ReactNode } from "react";
2+
import { Modal, Platform, Pressable, View } from "react-native";
3+
import { useSafeAreaInsets } from "react-native-safe-area-context";
4+
5+
import { AppText as Text } from "./AppText";
6+
7+
/** A page sheet with a title and Cancel, for the composer's search-and-pick sheets. */
8+
export function PickerSheet(props: {
9+
readonly title: string;
10+
readonly onClose: () => void;
11+
readonly children: ReactNode;
12+
}) {
13+
const insets = useSafeAreaInsets();
14+
return (
15+
<Modal presentationStyle="pageSheet" animationType="slide" onRequestClose={props.onClose}>
16+
<View
17+
className="flex-1 bg-sheet-solid"
18+
style={
19+
Platform.OS === "android"
20+
? { paddingTop: insets.top, paddingBottom: insets.bottom }
21+
: undefined
22+
}
23+
>
24+
<View className="flex-row items-center justify-between p-4">
25+
<Text className="text-lg text-foreground">{props.title}</Text>
26+
<Pressable accessibilityRole="button" onPress={props.onClose} className="p-3">
27+
<Text className="text-foreground">Cancel</Text>
28+
</Pressable>
29+
</View>
30+
{props.children}
31+
</View>
32+
</Modal>
33+
);
34+
}

0 commit comments

Comments
 (0)