Compare commits

..
Author SHA1 Message Date
Cursor Agent 1cc9019479 fix: skip idle terminal.onEvent subscription and release pruned terminal buffers
- connection.ts: Only subscribe to client.terminal.onEvent when
  applyTerminalEvent handler is provided. No production caller passes
  this handler, so the subscription was a no-op wasting WebSocket traffic.

- terminalSessionState.ts: Reset buffer atoms to EMPTY_TERMINAL_BUFFER_STATE
  when metadata snapshot pruning removes terminals no longer reported by
  the server. Releases up to 512KB of retained string data per pruned
  terminal session on long-running clients.
2026-05-22 02:39:23 +00:00
Julius Marminge 4db082a2d2 Unify mobile new-task and project sheet headers
- Extract shared new-task sheet header
- Refresh add-project form spacing and controls
- Align project creation screens with the new sheet layout
2026-05-21 19:18:55 -07:00
8 changed files with 321 additions and 131 deletions

No files matched your search

+2 -11
View File
@@ -8,6 +8,7 @@ import { useThemeColor } from "../../lib/useThemeColor";
import { AppText as Text } from "../../components/AppText";
import { ProjectFavicon } from "../../components/ProjectFavicon";
import { NewTaskSheetHeader } from "../../features/threads/NewTaskSheetHeader";
import { groupProjectsByRepository } from "../../lib/repositoryGroups";
import { type RemoteCatalogState, useRemoteCatalog } from "../../state/use-remote-catalog";
import { useRemoteEnvironmentState } from "../../state/use-remote-environment-registry";
@@ -103,17 +104,7 @@ export default function NewTaskRoute() {
<View collapsable={false} className="flex-1 bg-sheet">
<Stack.Screen options={{ headerShown: false }} />
<View style={{ minHeight: 16, paddingTop: 8 }} />
<View className="items-center gap-1 px-5 pb-3 pt-4">
<Text
className="text-[12px] font-t3-bold uppercase text-foreground-muted"
style={{ letterSpacing: 1 }}
>
New task
</Text>
<Text className="text-[28px] font-t3-bold">Choose project</Text>
</View>
<NewTaskSheetHeader title="Choose project" />
<ScrollView
showsVerticalScrollIndicator={false}
@@ -29,7 +29,6 @@ import * as Arr from "effect/Array";
import * as Order from "effect/Order";
import { AppText as Text, AppTextInput as TextInput } from "../../components/AppText";
import { ControlPill } from "../../components/ControlPill";
import { ErrorBanner } from "../../components/ErrorBanner";
import { SourceControlIcon } from "../../components/SourceControlIcon";
import { useThemeColor } from "../../lib/useThemeColor";
@@ -42,6 +41,7 @@ import {
refreshSourceControlDiscoveryForEnvironment,
useSourceControlDiscovery,
} from "../../state/use-source-control-discovery";
import { NewTaskSheetHeader } from "../threads/NewTaskSheetHeader";
interface EnvironmentOption {
readonly environmentId: EnvironmentId;
@@ -115,21 +115,21 @@ function AddProjectShell(props: {
return (
<View className="flex-1 bg-sheet">
<View className="flex-row items-center justify-between px-5 pb-1 pt-3">
<ControlPill
icon={props.closeToNew ? "xmark" : "chevron.left"}
onPress={() => router.back()}
/>
<Text className="text-[17px] font-t3-bold">{props.title}</Text>
<View className="h-11 w-11" />
</View>
<NewTaskSheetHeader
eyebrow="New project"
title={props.title}
control={{
icon: props.closeToNew ? "xmark" : "chevron.left",
onPress: () => router.back(),
}}
/>
<ScrollView
keyboardShouldPersistTaps="handled"
contentInsetAdjustmentBehavior="automatic"
contentContainerStyle={{
paddingHorizontal: 18,
paddingTop: 8,
paddingHorizontal: 20,
paddingTop: 16,
paddingBottom: Math.max(insets.bottom, 18) + 18,
gap: 10,
}}
@@ -141,7 +141,7 @@ function AddProjectShell(props: {
}
function ListSection(props: { readonly children: ReactNode }) {
return <View className="overflow-hidden rounded-2xl bg-card">{props.children}</View>;
return <View className="overflow-hidden rounded-[24px] bg-card">{props.children}</View>;
}
function ListRow(props: {
@@ -196,6 +196,48 @@ function ListRow(props: {
);
}
function PrimaryActionButton(props: {
readonly label: string;
readonly disabled?: boolean;
readonly loading?: boolean;
readonly onPress: () => void;
}) {
const primaryForeground = useThemeColor("--color-primary-foreground");
return (
<Pressable
disabled={props.disabled}
onPress={props.onPress}
className="h-12 items-center justify-center rounded-full bg-primary active:opacity-70 disabled:opacity-45"
>
{props.loading ? (
<ActivityIndicator color={String(primaryForeground)} />
) : (
<Text className="text-[14px] font-t3-bold text-primary-foreground">{props.label}</Text>
)}
</Pressable>
);
}
function ProjectPathInput(props: {
readonly value: string;
readonly onChangeText: (value: string) => void;
readonly onSubmit: () => void;
}) {
return (
<TextInput
className="h-12 min-h-12 rounded-[24px] px-4 py-0 text-[15px] leading-[20px]"
value={props.value}
onChangeText={props.onChangeText}
autoCapitalize="none"
autoCorrect={false}
placeholder="~/projects/my-app"
returnKeyType="done"
onSubmitEditing={props.onSubmit}
/>
);
}
function useEnvironmentOptions(): ReadonlyArray<EnvironmentOption> {
const { serverConfigByEnvironmentId } = useRemoteCatalog();
const { savedConnectionsById } = useRemoteEnvironmentState();
@@ -321,7 +363,7 @@ export function AddProjectSourceScreen() {
}, [selectedEnvironment]);
return (
<AddProjectShell title="Add project" closeToNew>
<AddProjectShell title="Select source" closeToNew>
{environmentOptions.length === 0 ? <EmptyEnvironmentState /> : null}
{environmentOptions.length > 1 ? (
@@ -362,7 +404,6 @@ export function AddProjectSourceScreen() {
{selectedEnvironment ? (
<>
<SectionTitle>Sources</SectionTitle>
<ListSection>
<ListRow
title="Local folder"
@@ -473,7 +514,6 @@ export function AddProjectRepositoryScreen() {
const params = useLocalSearchParams<{ environmentId?: string; source?: string }>();
const environment = useEnvironmentFromParam();
const source = sourceFromParam(params.source);
const primaryForeground = useThemeColor("--color-primary-foreground");
const [repositoryInput, setRepositoryInput] = useState("");
const [isSubmitting, setIsSubmitting] = useState(false);
const [error, setError] = useState<string | null>(null);
@@ -524,7 +564,7 @@ export function AddProjectRepositoryScreen() {
<AddProjectShell title={source === "url" ? "Git URL" : addProjectRemoteSourceLabel(source)}>
{error ? <ErrorBanner message={error} /> : null}
<TextInput
className="h-12 min-h-12 rounded-xl px-3 py-0 text-[15px] leading-[20px]"
className="h-12 min-h-12 rounded-[24px] px-4 py-0 text-[15px] leading-[20px]"
value={repositoryInput}
onChangeText={setRepositoryInput}
autoCapitalize="none"
@@ -537,19 +577,12 @@ export function AddProjectRepositoryScreen() {
returnKeyType="next"
onSubmitEditing={() => void lookupRepository()}
/>
<Pressable
<PrimaryActionButton
label={source === "url" ? "Continue" : "Lookup repository"}
disabled={isSubmitting || repositoryInput.trim().length === 0}
onPress={() => void lookupRepository()}
className="h-11 items-center justify-center rounded-full bg-primary active:opacity-70 disabled:opacity-45"
>
{isSubmitting ? (
<ActivityIndicator color={String(primaryForeground)} />
) : (
<Text className="text-[14px] font-t3-bold text-primary-foreground">
{source === "url" ? "Continue" : "Lookup repository"}
</Text>
)}
</Pressable>
loading={isSubmitting}
/>
</AddProjectShell>
);
}
@@ -643,7 +676,6 @@ function FolderBrowser(props: {
export function AddProjectLocalFolderScreen() {
const environment = useEnvironmentFromParam();
const createProject = useCreateProject(environment);
const primaryForeground = useThemeColor("--color-primary-foreground");
const [pathInput, setPathInput] = useState(() =>
getAddProjectInitialQuery(environment?.baseDirectory),
);
@@ -683,27 +715,17 @@ export function AddProjectLocalFolderScreen() {
{error ? <ErrorBanner message={error} /> : null}
{environment ? (
<>
<TextInput
className="h-12 min-h-12 rounded-xl px-3 py-0 text-[15px] leading-[20px]"
<ProjectPathInput
value={pathInput}
onChangeText={setPathInput}
autoCapitalize="none"
autoCorrect={false}
placeholder="~/projects/my-app"
returnKeyType="done"
onSubmitEditing={() => void submitPath()}
onSubmit={() => void submitPath()}
/>
<Pressable
<PrimaryActionButton
label="Add project"
disabled={isSubmitting}
onPress={() => void submitPath()}
className="h-11 items-center justify-center rounded-full bg-primary active:opacity-70"
>
{isSubmitting ? (
<ActivityIndicator color={String(primaryForeground)} />
) : (
<Text className="text-[14px] font-t3-bold text-primary-foreground">Add project</Text>
)}
</Pressable>
loading={isSubmitting}
/>
<FolderBrowser
environment={environment}
pathInput={pathInput}
@@ -725,7 +747,6 @@ export function AddProjectDestinationScreen() {
}>();
const environment = useEnvironmentFromParam();
const createProject = useCreateProject(environment);
const primaryForeground = useThemeColor("--color-primary-foreground");
const remoteUrl = stringParam(params.remoteUrl);
const repositoryTitle = stringParam(params.repositoryTitle);
const [pathInput, setPathInput] = useState(() =>
@@ -772,7 +793,7 @@ export function AddProjectDestinationScreen() {
<AddProjectShell title="Clone destination">
{error ? <ErrorBanner message={error} /> : null}
{repositoryTitle ? (
<View className="rounded-xl bg-card px-3.5 py-2.5">
<View className="rounded-[24px] bg-card px-4 py-3">
<Text className="text-[14px] font-t3-bold">{repositoryTitle}</Text>
<Text className="mt-0.5 text-[12px] text-foreground-muted" numberOfLines={2}>
{remoteUrl}
@@ -781,29 +802,17 @@ export function AddProjectDestinationScreen() {
) : null}
{environment ? (
<>
<TextInput
className="h-12 min-h-12 rounded-xl px-3 py-0 text-[15px] leading-[20px]"
<ProjectPathInput
value={pathInput}
onChangeText={setPathInput}
autoCapitalize="none"
autoCorrect={false}
placeholder="~/projects/my-app"
returnKeyType="done"
onSubmitEditing={() => void submitPath()}
onSubmit={() => void submitPath()}
/>
<Pressable
<PrimaryActionButton
label="Clone project"
disabled={isSubmitting || !remoteUrl}
onPress={() => void submitPath()}
className="h-11 items-center justify-center rounded-full bg-primary active:opacity-70 disabled:opacity-45"
>
{isSubmitting ? (
<ActivityIndicator color={String(primaryForeground)} />
) : (
<Text className="text-[14px] font-t3-bold text-primary-foreground">
Clone project
</Text>
)}
</Pressable>
loading={isSubmitting}
/>
<FolderBrowser
environment={environment}
pathInput={pathInput}
@@ -0,0 +1,175 @@
import { DEFAULT_TERMINAL_ID, type EnvironmentId, type ThreadId } from "@t3tools/contracts";
import { SymbolView } from "expo-symbols";
import { memo, useCallback, useEffect, useRef, useState } from "react";
import { Pressable, View } from "react-native";
import { AppText as Text } from "../../components/AppText";
import { getEnvironmentClient } from "../../state/environment-session-registry";
import {
attachTerminalSession,
useTerminalSession,
useTerminalSessionTarget,
} from "../../state/use-terminal-session";
import { TerminalSurface } from "./NativeTerminalSurface";
import { hasNativeTerminalSurface } from "./nativeTerminalModule";
import { terminalDebugLog } from "./terminalDebugLog";
interface ThreadTerminalPanelProps {
readonly environmentId: EnvironmentId;
readonly threadId: ThreadId;
readonly cwd: string;
readonly worktreePath: string | null;
readonly visible: boolean;
readonly onClose: () => void;
}
const DEFAULT_TERMINAL_COLS = 80;
const DEFAULT_TERMINAL_ROWS = 24;
export const ThreadTerminalPanel = memo(function ThreadTerminalPanel(
props: ThreadTerminalPanelProps,
) {
const nativeTerminalAvailable = hasNativeTerminalSurface();
const terminalId = DEFAULT_TERMINAL_ID;
const target = useTerminalSessionTarget({
environmentId: props.environmentId,
threadId: props.threadId,
terminalId,
});
const terminal = useTerminalSession(target);
const [lastGridSize, setLastGridSize] = useState({
cols: DEFAULT_TERMINAL_COLS,
rows: DEFAULT_TERMINAL_ROWS,
});
const lastGridSizeRef = useRef(lastGridSize);
lastGridSizeRef.current = lastGridSize;
const terminalKey = `${props.environmentId}:${props.threadId}:${terminalId}`;
const isRunning = terminal.status === "running" || terminal.status === "starting";
useEffect(() => {
if (!props.visible) {
return;
}
const client = getEnvironmentClient(props.environmentId);
if (!client) {
terminalDebugLog("panel:attach-skip", {
reason: "no-environment-client",
environmentId: props.environmentId,
});
return;
}
terminalDebugLog("panel:attach", {
environmentId: props.environmentId,
threadId: props.threadId,
terminalId,
});
return attachTerminalSession({
environmentId: props.environmentId,
client,
terminal: {
threadId: props.threadId,
terminalId,
cwd: props.cwd,
worktreePath: props.worktreePath,
cols: lastGridSizeRef.current.cols,
rows: lastGridSizeRef.current.rows,
},
});
}, [
props.cwd,
props.environmentId,
props.threadId,
props.worktreePath,
props.visible,
terminalId,
]);
const handleInput = useCallback(
(data: string) => {
const client = getEnvironmentClient(props.environmentId);
if (!client || !isRunning) {
return;
}
void client.terminal.write({
threadId: props.threadId,
terminalId,
data,
});
},
[isRunning, props.environmentId, props.threadId, terminalId],
);
const handleResize = useCallback(
(size: { readonly cols: number; readonly rows: number }) => {
if (size.cols === lastGridSize.cols && size.rows === lastGridSize.rows) {
return;
}
setLastGridSize(size);
const client = getEnvironmentClient(props.environmentId);
if (!client || !isRunning) {
return;
}
void client.terminal.resize({
threadId: props.threadId,
terminalId,
cols: size.cols,
rows: size.rows,
});
},
[
isRunning,
lastGridSize.cols,
lastGridSize.rows,
props.environmentId,
props.threadId,
terminalId,
],
);
if (!props.visible) {
return null;
}
return (
<View className="absolute inset-x-3 bottom-28 top-28 overflow-hidden rounded-[8px] border border-white/10 bg-neutral-950 shadow-2xl">
<View className="flex-row items-center justify-between border-b border-white/10 px-3 py-2">
<View className="min-w-0 flex-1">
<Text className="font-t3-bold text-[13px] text-neutral-100" numberOfLines={1}>
Terminal
</Text>
<Text className="text-[11px] text-neutral-500" numberOfLines={1}>
{nativeTerminalAvailable ? "Native Ghostty surface" : "Text fallback active"}
</Text>
</View>
<View className="flex-row items-center gap-2">
{terminal.error ? (
<Text className="max-w-44 text-right text-[11px] text-red-300" numberOfLines={1}>
{terminal.error}
</Text>
) : null}
<Pressable
className="h-8 w-8 items-center justify-center rounded-[8px] bg-white/10"
onPress={props.onClose}
>
<SymbolView name="xmark" size={13} tintColor="#e5e5e5" type="monochrome" />
</Pressable>
</View>
</View>
<TerminalSurface
terminalKey={terminalKey}
buffer={terminal.buffer}
isRunning={isRunning}
onInput={handleInput}
onResize={handleResize}
style={{ flex: 1 }}
/>
</View>
);
});
@@ -725,7 +725,6 @@ export function ThreadTerminalRouteScreen() {
router,
selectedThread?.environmentId,
selectedThread?.id,
selectedThreadDetail?.worktreePath,
selectedThreadProject?.workspaceRoot,
terminalId,
]);
@@ -1,16 +1,15 @@
import { MenuView } from "@react-native-menu/menu";
import { useRouter } from "expo-router";
import { SymbolView } from "expo-symbols";
import { TextInputWrapper } from "expo-paste-input";
import { useCallback, useEffect, useMemo } from "react";
import { Pressable, View, useColorScheme } from "react-native";
import { View, useColorScheme } from "react-native";
import { KeyboardStickyView } from "react-native-keyboard-controller";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { useThemeColor } from "../../lib/useThemeColor";
import { EnvironmentId, type ModelSelection } from "@t3tools/contracts";
import { AppText as Text, AppTextInput as TextInput } from "../../components/AppText";
import { AppTextInput as TextInput } from "../../components/AppText";
import { ComposerAttachmentStrip } from "../../components/ComposerAttachmentStrip";
import { ControlPill } from "../../components/ControlPill";
import { ProviderIcon } from "../../components/ProviderIcon";
@@ -20,6 +19,7 @@ import { buildThreadRoutePath } from "../../lib/routes";
import { useRemoteCatalog } from "../../state/use-remote-catalog";
import { useNativePaste } from "../../lib/useNativePaste";
import { CLAUDE_AGENT_EFFORT_OPTIONS } from "./claudeEffortOptions";
import { NewTaskSheetHeader } from "./NewTaskSheetHeader";
import { branchBadgeLabel, useNewTaskFlow } from "./new-task-flow-provider";
import { useProjectActions } from "./use-project-actions";
@@ -50,7 +50,6 @@ export function NewTaskDraftScreen(props: {
const controlsBottomPadding = Math.max(insets.bottom, 10);
const { logicalProjects, selectedProject, setProject } = flow;
const iconColor = useThemeColor("--color-icon");
const borderColor = useThemeColor("--color-border");
useEffect(() => {
@@ -394,48 +393,21 @@ export function NewTaskDraftScreen(props: {
if (!selectedProject) {
return (
<View className="flex-1 bg-sheet">
<View style={{ minHeight: 16, paddingTop: 8 }} />
<View className="items-center gap-1 px-5 pb-3 pt-4">
<Text
className="text-[12px] font-t3-bold uppercase text-foreground-muted"
style={{ letterSpacing: 1 }}
>
New task
</Text>
<Text className="text-[28px] font-t3-bold">Loading task</Text>
</View>
<NewTaskSheetHeader title="Loading task" />
</View>
);
}
return (
<View className="flex-1 bg-sheet">
<View style={{ minHeight: 16, paddingTop: 8 }} />
<View className="items-center gap-1 px-5 pb-3 pt-4">
{flow.logicalProjects.length > 1 ? (
<Pressable
className="absolute left-3 top-4 h-9 w-9 items-center justify-center rounded-full bg-subtle"
style={{ zIndex: 1 }}
onPress={() => router.back()}
>
<SymbolView
name="chevron.left"
size={16}
tintColor={iconColor}
type="monochrome"
weight="medium"
/>
</Pressable>
) : null}
<Text
className="text-[12px] font-t3-bold uppercase text-foreground-muted"
style={{ letterSpacing: 1 }}
>
New task
</Text>
<Text className="text-[28px] font-t3-bold">{selectedProject.title}</Text>
</View>
<NewTaskSheetHeader
title={selectedProject.title}
control={
flow.logicalProjects.length > 1
? { icon: "chevron.left", onPress: () => router.back() }
: undefined
}
/>
<View style={{ flex: 1, paddingHorizontal: 20, paddingTop: 8 }}>
<TextInputWrapper
@@ -0,0 +1,46 @@
import { SymbolView } from "expo-symbols";
import { Pressable, View } from "react-native";
import { AppText as Text } from "../../components/AppText";
import { useThemeColor } from "../../lib/useThemeColor";
export function NewTaskSheetHeader(props: {
readonly eyebrow?: string;
readonly title: string;
readonly control?: {
readonly icon: "chevron.left" | "xmark";
readonly onPress: () => void;
};
}) {
const iconColor = useThemeColor("--color-icon");
return (
<>
<View style={{ minHeight: 16, paddingTop: 8 }} />
<View className="items-center gap-1 px-5 pb-3 pt-4">
{props.control ? (
<Pressable
className="absolute left-3 top-4 h-9 w-9 items-center justify-center rounded-full bg-subtle"
style={{ zIndex: 1 }}
onPress={props.control.onPress}
>
<SymbolView
name={props.control.icon}
size={16}
tintColor={iconColor}
type="monochrome"
weight="medium"
/>
</Pressable>
) : null}
<Text
className="text-[12px] font-t3-bold uppercase text-foreground-muted"
style={{ letterSpacing: 1 }}
>
{props.eyebrow ?? "New task"}
</Text>
<Text className="text-[28px] font-t3-bold">{props.title}</Text>
</View>
</>
);
}
@@ -143,11 +143,13 @@ export function createEnvironmentConnection(
},
);
const unsubTerminalEvent = input.client.terminal.onEvent(
(event: Parameters<Parameters<WsRpcClient["terminal"]["onEvent"]>[0]>[0]) => {
input.applyTerminalEvent?.(event, environmentId);
},
);
const unsubTerminalEvent = input.applyTerminalEvent
? input.client.terminal.onEvent(
(event: Parameters<Parameters<WsRpcClient["terminal"]["onEvent"]>[0]>[0]) => {
input.applyTerminalEvent!(event, environmentId);
},
)
: () => undefined;
const cleanup = () => {
disposed = true;
@@ -242,24 +242,16 @@ function latestTimestamp(left: string | null, right: string | null): string | nu
return Date.parse(left) >= Date.parse(right) ? left : right;
}
function isBufferTerminalStatus(buffer: TerminalBufferState): boolean {
return (
buffer.version > 0 &&
(buffer.status === "exited" || buffer.status === "closed" || buffer.status === "error")
);
}
function combineSessionState(
summary: TerminalSummary | null,
buffer: TerminalBufferState,
): TerminalSessionState {
const bufferTerminal = isBufferTerminalStatus(buffer);
return {
summary,
buffer: buffer.buffer,
status: bufferTerminal ? buffer.status : (summary?.status ?? buffer.status),
status: summary?.status ?? buffer.status,
error: buffer.error,
hasRunningSubprocess: bufferTerminal ? false : (summary?.hasRunningSubprocess ?? false),
hasRunningSubprocess: summary?.hasRunningSubprocess ?? false,
updatedAt: latestTimestamp(summary?.updatedAt ?? null, buffer.updatedAt),
version: buffer.version,
};
@@ -410,6 +402,10 @@ export function createTerminalSessionManager(config: TerminalSessionManagerConfi
for (const key of Object.keys(next)) {
if (!retainedKeys.has(key)) {
const removedEntry = next[key];
if (removedEntry) {
setBuffer(removedEntry.target, EMPTY_TERMINAL_BUFFER_STATE);
}
delete next[key];
}
}