Skip to content

Commit 608028b

Browse files
committed
Merge remote-tracking branch 'origin/main' into fix/scheduled-task-settings-default-branch
# Conflicts: # apps/mobile/src/features/settings/ScheduledTaskPickerScreens.tsx # apps/mobile/src/features/settings/SettingsScheduledTasksRouteScreen.tsx # apps/mobile/src/features/settings/scheduledTaskDraft.ts # apps/web/src/components/settings/scheduledTasksSettings.logic.ts
2 parents 3aa7239 + 6417151 commit 608028b

52 files changed

Lines changed: 841 additions & 141 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.

‎apps/mobile/src/Stack.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ import {
110110
import {
111111
ScheduledTaskModelPickerRouteScreen,
112112
ScheduledTaskBranchPickerRouteScreen,
113+
ScheduledTaskThreadPickerRouteScreen,
113114
} from "./features/settings/ScheduledTaskPickerScreens";
114115
import { SettingsKeyboardRouteScreen } from "./features/settings/SettingsKeyboardRouteScreen";
115116
import { SettingsLegalRouteScreen } from "./features/settings/SettingsLegalRouteScreen";
@@ -301,6 +302,10 @@ const SETTINGS_SCREENS = {
301302
screen: ScheduledTaskBranchPickerRouteScreen,
302303
options: settingsPage("Base branch"),
303304
}),
305+
SettingsScheduledTaskThread: createNativeStackScreen({
306+
screen: ScheduledTaskThreadPickerRouteScreen,
307+
options: settingsPage("Destination"),
308+
}),
304309
SettingsScheduledTaskModel: createNativeStackScreen({
305310
screen: ScheduledTaskModelPickerRouteScreen,
306311
options: THREAD_SETTINGS_ROUTE,

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

Lines changed: 175 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,41 @@
11
import { useNavigation } from "@react-navigation/native";
2+
import { isListedThreadLineage } from "@t3tools/contracts";
23
import * as Haptics from "expo-haptics";
3-
import { useMemo, useState } from "react";
4+
import { useMemo, useRef, useState } from "react";
5+
import { FlatList, Platform, type TextInputInstance, View } from "react-native";
6+
import { useSafeAreaInsets } from "react-native-safe-area-context";
47

58
import { AppText as Text } from "../../components/ui/AppText";
9+
import { SearchField } from "../../components/ui/SearchField";
10+
import { SelectionRow } from "../../components/ui/SelectionRow";
11+
import { Toolbar } from "../../components/ui/Toolbar";
612
import { buildModelOptions, groupByProvider } from "../../lib/modelOptions";
713
import { resolveProviderOptionDescriptors } from "../../lib/providerOptions";
8-
import { useEnvironmentServerConfig, useProjects } from "../../state/entities";
9-
import { useDebouncedValue, usePaginatedBranches } from "../../state/queries";
14+
import { NativeStackScreenOptions } from "../../native/StackHeader";
15+
import { useNativeMailSearchToolbar } from "../../native/use-native-mail-search-toolbar";
16+
import {
17+
useEnvironmentServerConfig,
18+
useProjects,
19+
useVisibleThreadShells,
20+
} from "../../state/entities";
21+
import { useDebouncedValue, usePaginatedBranches, useThreadSearch } from "../../state/queries";
22+
import {
23+
createNativeMailSearchToolbarItem,
24+
NATIVE_MAIL_SEARCH_TOOLBAR_CONTENT_INSET,
25+
} from "../layout/native-mail-search-toolbar";
1026
import { BranchPickerScreen } from "../threads/NewTaskContextPickerScreens";
1127
import { ThreadSettingsPickerScreen } from "../threads/ThreadSettingsSheet";
1228
import { SettingsScreen } from "./components/SettingsScreen";
13-
import { useScheduledTaskEditor } from "./scheduled-task-editor";
14-
import { scheduledTaskWorktreeBaseRef } from "./scheduledTaskDraft";
29+
import {
30+
NEW_THREAD_DESTINATION_LABEL,
31+
useScheduledTaskDestinationLabel,
32+
useScheduledTaskEditor,
33+
} from "./scheduled-task-editor";
34+
import {
35+
moveDraftToThread,
36+
scheduledTaskWorktreeBaseRef,
37+
unbindDraftFromThread,
38+
} from "./scheduledTaskDraft";
1539

1640
function MissingTaskDraft() {
1741
return (
@@ -169,3 +193,149 @@ export function ScheduledTaskBranchPickerRouteScreen() {
169193
/>
170194
);
171195
}
196+
197+
const THREAD_SEARCH_PLACEHOLDER = "Search threads, including older ones";
198+
199+
export function ScheduledTaskThreadPickerRouteScreen() {
200+
const navigation = useNavigation();
201+
const insets = useSafeAreaInsets();
202+
const usesNativeMailSearchToolbar = useNativeMailSearchToolbar();
203+
const searchRef = useRef<TextInputInstance>(null);
204+
const { editor, setEditor } = useScheduledTaskEditor();
205+
const environmentId = editor?.environmentId ?? null;
206+
const projectId = editor?.draft.projectId ?? null;
207+
const threadId = editor?.draft.threadId ?? null;
208+
const currentLabel = useScheduledTaskDestinationLabel(environmentId, threadId);
209+
const shells = useVisibleThreadShells();
210+
const [query, setQuery] = useState("");
211+
// Mounts older settled threads matching the query, which shells may leave out.
212+
useThreadSearch(
213+
environmentId !== null && projectId !== null ? [environmentId] : [],
214+
query,
215+
projectId === null ? { titlesOnly: true } : { titlesOnly: true, projectIds: [projectId] },
216+
);
217+
218+
if (!editor) return <MissingTaskDraft />;
219+
220+
const search = query.trim().toLocaleLowerCase();
221+
const rows = [
222+
...(search ? [] : [{ key: "new-thread", title: NEW_THREAD_DESTINATION_LABEL, thread: null }]),
223+
...(threadId !== null && currentLabel.toLocaleLowerCase().includes(search)
224+
? [{ key: threadId, title: currentLabel, thread: null }]
225+
: []),
226+
...shells
227+
.filter(
228+
(thread) =>
229+
thread.environmentId === environmentId &&
230+
thread.projectId === projectId &&
231+
thread.id !== threadId &&
232+
thread.archivedAt === null &&
233+
isListedThreadLineage(thread.lineage) &&
234+
thread.title.toLocaleLowerCase().includes(search),
235+
)
236+
.sort((left, right) => right.updatedAt.localeCompare(left.updatedAt))
237+
.map((thread) => ({
238+
key: thread.id,
239+
title: thread.title.trim() || "Untitled thread",
240+
thread,
241+
})),
242+
];
243+
const selectedKey = threadId ?? (editor.draft.threadMode === "new_thread" ? "new-thread" : null);
244+
245+
return (
246+
<SettingsScreen title="Destination">
247+
{Platform.OS === "ios" ? (
248+
<NativeStackScreenOptions
249+
options={{
250+
unstable_headerToolbarItems: usesNativeMailSearchToolbar
251+
? () => [
252+
createNativeMailSearchToolbarItem({
253+
onSearchTextChange: setQuery,
254+
placeholder: THREAD_SEARCH_PLACEHOLDER,
255+
searchTextChangeId: "scheduled-task-thread-search-text",
256+
showsSearchDismissButton: true,
257+
}),
258+
]
259+
: undefined,
260+
headerSearchBarOptions: usesNativeMailSearchToolbar
261+
? undefined
262+
: {
263+
allowToolbarIntegration: true,
264+
autoCapitalize: "none",
265+
hideNavigationBar: false,
266+
hideWhenScrolling: false,
267+
obscureBackground: false,
268+
onCancelButtonPress: () => setQuery(""),
269+
onChangeText: (event) => setQuery(event.nativeEvent.text),
270+
placeholder: THREAD_SEARCH_PLACEHOLDER,
271+
},
272+
}}
273+
/>
274+
) : null}
275+
{Platform.OS === "ios" && !usesNativeMailSearchToolbar ? (
276+
<Toolbar placement="bottom">
277+
<Toolbar.SearchBarSlot />
278+
</Toolbar>
279+
) : null}
280+
<FlatList
281+
data={rows}
282+
keyExtractor={(row) => row.key}
283+
className="flex-1"
284+
contentInsetAdjustmentBehavior="automatic"
285+
automaticallyAdjustKeyboardInsets={Platform.OS === "ios"}
286+
keyboardDismissMode={Platform.OS === "ios" ? "interactive" : "on-drag"}
287+
keyboardShouldPersistTaps="handled"
288+
showsVerticalScrollIndicator={false}
289+
contentContainerStyle={{
290+
paddingHorizontal: 16,
291+
paddingTop: 16,
292+
paddingBottom: usesNativeMailSearchToolbar
293+
? NATIVE_MAIL_SEARCH_TOOLBAR_CONTENT_INSET + 16
294+
: Math.max(insets.bottom, 16) + 16,
295+
}}
296+
ListHeaderComponent={
297+
Platform.OS === "ios" ? undefined : (
298+
<View className="pb-4">
299+
<SearchField
300+
inputRef={searchRef}
301+
autoFocus={false}
302+
accessibilityLabel="Search threads"
303+
clearAccessibilityLabel="Clear thread search"
304+
onChangeText={setQuery}
305+
placeholder={THREAD_SEARCH_PLACEHOLDER}
306+
value={query}
307+
/>
308+
</View>
309+
)
310+
}
311+
ListEmptyComponent={
312+
<Text className="p-5 text-center text-sm text-foreground-muted">No matching threads</Text>
313+
}
314+
renderItem={({ item, index }) => (
315+
<SelectionRow
316+
title={item.title}
317+
selected={item.key === selectedKey}
318+
isFirst={index === 0}
319+
isLast={index === rows.length - 1}
320+
onPress={() => {
321+
void Haptics.selectionAsync();
322+
if (item.key !== selectedKey) {
323+
setEditor((current) =>
324+
current
325+
? {
326+
...current,
327+
draft: item.thread
328+
? moveDraftToThread(current.draft, item.thread)
329+
: { ...unbindDraftFromThread(current.draft), threadMode: "new_thread" },
330+
}
331+
: current,
332+
);
333+
}
334+
navigation.goBack();
335+
}}
336+
/>
337+
)}
338+
/>
339+
</SettingsScreen>
340+
);
341+
}

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

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,17 @@ import { SettingsScreen } from "./components/SettingsScreen";
7373
import { SettingsSection } from "./components/SettingsSection";
7474
import { useSettingsEnvironmentFilter, type SettingsTarget } from "./settings-environment-filter";
7575
import {
76+
changeDraftProject,
7677
editDraft,
7778
parseIntervalMinutes,
7879
scheduledTaskDefaultModel,
7980
scheduleFromDraft,
8081
scheduledTaskWorktreeBaseRef,
82+
unbindDraftFromThread,
8183
type ScheduledTaskDraft as Draft,
8284
} from "./scheduledTaskDraft";
8385
import { settingsTargetsForProject } from "./settings-environment-filter.logic";
84-
import { useScheduledTaskEditor } from "./scheduled-task-editor";
86+
import { useScheduledTaskDestinationLabel, useScheduledTaskEditor } from "./scheduled-task-editor";
8587
import {
8688
discardScheduledTaskEditor,
8789
markScheduledTaskEditorSaved,
@@ -98,6 +100,7 @@ type ScheduledTaskRoutes = {
98100
SettingsScheduledTaskEdit: undefined;
99101
SettingsScheduledTaskModel: undefined;
100102
SettingsScheduledTaskBranch: undefined;
103+
SettingsScheduledTaskThread: undefined;
101104
};
102105

103106
const DAYS = [
@@ -674,6 +677,7 @@ function TaskForm({
674677
});
675678
const worktreeBaseRef = scheduledTaskWorktreeBaseRef(draft.baseRef, automaticBaseRefs.refs);
676679
const config = useEnvironmentServerConfig(environmentId);
680+
const destinationLabel = useScheduledTaskDestinationLabel(environmentId, draft.threadId);
677681
const modelOptions = buildModelOptions(config, null, undefined, draft.projectId);
678682
// Existing webhook tasks keep the option so they can still switch to a timer.
679683
const webhookDenial = managedCapabilityDenial(config?.managedPolicy, "webhookTasks");
@@ -777,7 +781,7 @@ function TaskForm({
777781
modelSelection: draft.modelSelection,
778782
schedule,
779783
enabled: draft.enabled,
780-
threadId: draft.task?.threadId ?? null,
784+
threadId: draft.threadId,
781785
...(offersThreadModes ? { threadMode: draft.threadMode } : {}),
782786
workspaceStrategy:
783787
draft.workspace === "root"
@@ -890,8 +894,7 @@ function TaskForm({
890894
draft.modelSelection.instanceId,
891895
));
892896
setDraft({
893-
...draft,
894-
projectId: project.id,
897+
...changeDraftProject(draft, project.id),
895898
modelSelection: keepsExplicitModel
896899
? draft.modelSelection
897900
: scheduledTaskDefaultModel(config, project),
@@ -916,19 +919,21 @@ function TaskForm({
916919
/>
917920
</SettingsSection>
918921

919-
{offersThreadModes ? (
920-
<SettingsSection
921-
title="Destination"
922-
footer={
923-
draft.threadMode === "new_thread"
924-
? "Each run starts a new thread."
925-
: `${
926-
draft.threadMode === "continue"
927-
? "Runs continue one conversation."
928-
: "Runs share one thread, each in a fresh session without earlier runs' context."
929-
} The first run starts the thread. Deleting it also deletes this task.`
930-
}
931-
>
922+
<SettingsSection
923+
title="Destination"
924+
footer={
925+
draft.threadMode === "new_thread"
926+
? "Each run starts a new thread."
927+
: `${
928+
draft.threadMode === "continue"
929+
? "Runs continue one conversation."
930+
: "Runs share one thread, each in a fresh session without earlier runs' context."
931+
}${
932+
draft.threadId === null ? " The first run starts the thread." : ""
933+
} Deleting it also deletes this task.`
934+
}
935+
>
936+
{offersThreadModes ? (
932937
<SelectRow
933938
label="Runs go to"
934939
value={THREAD_MODE_LABELS[draft.threadMode]}
@@ -940,12 +945,27 @@ function TaskForm({
940945
}),
941946
)}
942947
onSelect={(id) => {
943-
if (id === "new_thread" || id === "continue" || id === "fresh_session")
948+
if (id === "new_thread")
949+
setDraft({ ...unbindDraftFromThread(draft), threadMode: id });
950+
else if (id === "continue" || id === "fresh_session")
944951
setDraft({ ...draft, threadMode: id });
945952
}}
946953
/>
947-
</SettingsSection>
948-
) : null}
954+
) : null}
955+
{!offersThreadModes || draft.threadMode !== "new_thread" ? (
956+
<PickerRow
957+
label="Thread"
958+
borderTop={offersThreadModes}
959+
value={
960+
draft.threadId === null && draft.threadMode !== "new_thread"
961+
? "Started by the first run"
962+
: destinationLabel
963+
}
964+
onPress={() => navigation.navigate("SettingsScheduledTaskThread")}
965+
disabled={!draft.projectId || saving || dictationPending || environmentUnavailable}
966+
/>
967+
) : null}
968+
</SettingsSection>
949969

950970
<SettingsSection title="Workspace">
951971
<SelectRow

‎apps/mobile/src/features/settings/components/ScheduledTaskPromptField.tsx‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function ScheduledTaskPromptField(props: {
2929
return (
3030
<View className="gap-2 border-t border-border-subtle px-4 py-3">
3131
<Text className="text-sm text-foreground-muted">Prompt</Text>
32-
<View className="relative">
32+
<View className="flex-row items-end">
3333
<TextInput
3434
accessibilityLabel="Prompt"
3535
value={props.value}
@@ -42,18 +42,16 @@ export function ScheduledTaskPromptField(props: {
4242
textAlignVertical="top"
4343
placeholder="What should the agent do each time?"
4444
placeholderTextColorClassName="accent-foreground-muted"
45-
className="max-h-40 min-h-24 font-sans text-base text-foreground"
45+
className="max-h-40 min-h-24 min-w-0 flex-1 font-sans text-base text-foreground"
4646
/>
4747
{showsIdleTrigger ? (
48-
<View className="absolute right-0 bottom-0 rounded-full bg-card">
49-
<ComposerDictationStartAction
50-
state={voice.state}
51-
isAvailable={voice.isAvailable}
52-
disabled={props.disabled}
53-
onStart={voice.start}
54-
onCancel={voice.cancel}
55-
/>
56-
</View>
48+
<ComposerDictationStartAction
49+
state={voice.state}
50+
isAvailable={voice.isAvailable}
51+
disabled={props.disabled}
52+
onStart={voice.start}
53+
onCancel={voice.cancel}
54+
/>
5755
) : null}
5856
</View>
5957
<ComposerDictationError

0 commit comments

Comments
 (0)