Skip to content

Commit 50ccd7c

Browse files
committed
feat(web): start a thread without a project
The server advertises a plain chats folder under its data dir in ServerConfig.chatWorkspaceRoot. Choosing "Just chat" from the draft headline picker, the no-projects hero, the add-project palette, or the mobile project picker adds an ordinary project rooted there (once per environment) and targets the draft at it. Everything downstream is the existing non-git project path, so git controls, checkpoints, and diffs stay out of the way without any chat-specific branching.
1 parent d4d5d12 commit 50ccd7c

8 files changed

Lines changed: 398 additions & 54 deletions

File tree

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

Lines changed: 155 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ import {
77
type StaticScreenProps,
88
} from "@react-navigation/native";
99
import { SymbolView } from "../../components/AppSymbol";
10+
import {
11+
buildChatProjectCreateCommand,
12+
canCreateProjectInEnvironment,
13+
findChatProject,
14+
} from "@t3tools/client-runtime/operations/projects";
1015
import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell";
16+
import { CommandId, ProjectId } from "@t3tools/contracts";
17+
import * as Cause from "effect/Cause";
18+
import { AsyncResult } from "effect/unstable/reactivity";
1119
import { useEffect, useRef } from "react";
1220
import { ActivityIndicator, Alert, Platform, Pressable, View } from "react-native";
1321
import { useSafeAreaInsets } from "react-native-safe-area-context";
@@ -18,7 +26,11 @@ import { MaterialButton } from "../../components/MaterialButton";
1826
import { ScreenScrollView as ScrollView } from "../../components/ScreenScrollView";
1927
import { AppText as Text } from "../../components/AppText";
2028
import { ProjectFavicon } from "../../components/ProjectFavicon";
21-
import { useProjects } from "../../state/entities";
29+
import { uuidv4 } from "../../lib/uuid";
30+
import { useProjects, useServerConfigs, waitForProject } from "../../state/entities";
31+
import { projectEnvironment } from "../../state/projects";
32+
import { useAtomCommand } from "../../state/use-atom-command";
33+
import { useRemoteConnectionStatus } from "../../state/use-remote-environment-registry";
2234
import type { WorkspaceState } from "../../state/workspaceModel";
2335
import { useWorkspaceState } from "../../state/workspace";
2436
import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
@@ -115,6 +127,26 @@ export function NewTaskRouteScreen({ route }: StaticScreenProps<NewTaskRoutePara
115127
project.id === incomingShare.destination?.projectId,
116128
) ?? null)
117129
: null;
130+
const serverConfigs = useServerConfigs();
131+
const { connectedEnvironments } = useRemoteConnectionStatus();
132+
const createProject = useAtomCommand(projectEnvironment.create, { reportFailure: false });
133+
// "Just chat" needs a connected environment whose server offers a chat
134+
// folder. Prefer the environment the picker is already scoped to.
135+
const chatEnvironment =
136+
connectedEnvironments.find(
137+
(environment) =>
138+
environment.environmentId === selectedEnvironmentId &&
139+
canCreateProjectInEnvironment(environment.connectionState),
140+
) ??
141+
connectedEnvironments.find((environment) =>
142+
canCreateProjectInEnvironment(environment.connectionState),
143+
) ??
144+
null;
145+
const chatWorkspaceRoot = chatEnvironment
146+
? (serverConfigs.get(chatEnvironment.environmentId)?.chatWorkspaceRoot ?? null)
147+
: null;
148+
const canJustChat =
149+
chatEnvironment !== null && chatWorkspaceRoot !== null && reservedDestinationProject === null;
118150

119151
async function selectProject(project: EnvironmentProject): Promise<void> {
120152
if (incomingShare?.destination && !reservedDestinationProject) {
@@ -148,6 +180,43 @@ export function NewTaskRouteScreen({ route }: StaticScreenProps<NewTaskRoutePara
148180
);
149181
}
150182

183+
async function startChat(): Promise<void> {
184+
if (!chatEnvironment || chatWorkspaceRoot === null) return;
185+
const environmentId = chatEnvironment.environmentId;
186+
const existing = findChatProject({ projects, environmentId, chatWorkspaceRoot });
187+
if (existing) {
188+
await selectProject(existing);
189+
return;
190+
}
191+
const projectId = ProjectId.make(uuidv4());
192+
const result = await createProject({
193+
environmentId,
194+
input: buildChatProjectCreateCommand({
195+
commandId: CommandId.make(uuidv4()),
196+
projectId,
197+
chatWorkspaceRoot,
198+
createdAt: new Date().toISOString(),
199+
}),
200+
});
201+
if (AsyncResult.isFailure(result)) {
202+
const error = Cause.squash(result.cause);
203+
Alert.alert(
204+
"Could not start chat",
205+
error instanceof Error ? error.message : "The chat folder could not be created.",
206+
);
207+
return;
208+
}
209+
const project = await waitForProject({ environmentId, projectId });
210+
if (project === null) {
211+
Alert.alert(
212+
"Could not start chat",
213+
"The chat folder was created but has not reached this device yet. Pick Chats from the project list once it appears.",
214+
);
215+
return;
216+
}
217+
await selectProject(project);
218+
}
219+
151220
useEffect(() => {
152221
const destination = incomingShare?.destination;
153222
if (!destination) {
@@ -263,15 +332,24 @@ export function NewTaskRouteScreen({ route }: StaticScreenProps<NewTaskRoutePara
263332
{projectEmptyState.detail}
264333
</Text>
265334
{Platform.OS === "android" ? (
266-
<MaterialButton
267-
label={catalogState.hasReadyEnvironment ? "Add new project" : "Add environment"}
268-
tone="primary"
269-
onPress={() =>
270-
catalogState.hasReadyEnvironment
271-
? navigation.dispatch(StackActions.push("AddProject"))
272-
: navigation.navigate("ConnectionsNew")
273-
}
274-
/>
335+
<>
336+
<MaterialButton
337+
label={catalogState.hasReadyEnvironment ? "Add new project" : "Add environment"}
338+
tone="primary"
339+
onPress={() =>
340+
catalogState.hasReadyEnvironment
341+
? navigation.dispatch(StackActions.push("AddProject"))
342+
: navigation.navigate("ConnectionsNew")
343+
}
344+
/>
345+
{canJustChat ? (
346+
<MaterialButton
347+
label="Just chat"
348+
tone="secondary"
349+
onPress={() => void startChat()}
350+
/>
351+
) : null}
352+
</>
275353
) : !catalogState.hasReadyEnvironment ? (
276354
<Pressable
277355
className="mt-1 rounded-full bg-primary px-4 py-2.5 active:opacity-70"
@@ -282,14 +360,24 @@ export function NewTaskRouteScreen({ route }: StaticScreenProps<NewTaskRoutePara
282360
</Text>
283361
</Pressable>
284362
) : (
285-
<Pressable
286-
className="mt-1 rounded-full bg-primary px-4 py-2.5 active:opacity-70"
287-
onPress={() => navigation.dispatch(StackActions.push("AddProject"))}
288-
>
289-
<Text className="text-sm font-t3-bold text-primary-foreground">
290-
Add new project
291-
</Text>
292-
</Pressable>
363+
<>
364+
<Pressable
365+
className="mt-1 rounded-full bg-primary px-4 py-2.5 active:opacity-70"
366+
onPress={() => navigation.dispatch(StackActions.push("AddProject"))}
367+
>
368+
<Text className="text-sm font-t3-bold text-primary-foreground">
369+
Add new project
370+
</Text>
371+
</Pressable>
372+
{canJustChat ? (
373+
<Pressable
374+
className="rounded-full bg-subtle px-4 py-2.5 active:opacity-70"
375+
onPress={() => void startChat()}
376+
>
377+
<Text className="text-sm font-t3-bold text-foreground">Just chat</Text>
378+
</Pressable>
379+
) : null}
380+
</>
293381
)}
294382
</View>
295383
) : (
@@ -378,6 +466,55 @@ export function NewTaskRouteScreen({ route }: StaticScreenProps<NewTaskRoutePara
378466
})}
379467
</View>
380468
)}
469+
{canJustChat && projectScopes.length > 0 ? (
470+
Platform.OS === "android" ? (
471+
<View collapsable={false} className="overflow-hidden rounded-[28px] bg-card">
472+
<MaterialListRow
473+
title="Just chat"
474+
subtitle="Start a task without a repository"
475+
onPress={() => void startChat()}
476+
leading={
477+
<SymbolView
478+
name="bubble.left"
479+
size={22}
480+
tintColorClassName="accent-icon-muted"
481+
type="monochrome"
482+
/>
483+
}
484+
/>
485+
</View>
486+
) : (
487+
<View collapsable={false} className="overflow-hidden rounded-[24px] bg-card">
488+
<Pressable
489+
accessibilityRole="button"
490+
accessibilityLabel="Just chat"
491+
onPress={() => void startChat()}
492+
className="flex-row items-center gap-3 bg-card px-4 py-3.5"
493+
>
494+
<View className="h-7 w-7 items-center justify-center">
495+
<SymbolView
496+
name="bubble.left"
497+
size={18}
498+
tintColorClassName="accent-icon-muted"
499+
type="monochrome"
500+
/>
501+
</View>
502+
<View className="min-w-0 flex-1">
503+
<Text className="text-base font-t3-bold leading-snug">Just chat</Text>
504+
<Text className="text-xs leading-snug text-foreground-muted" numberOfLines={1}>
505+
Start a task without a repository
506+
</Text>
507+
</View>
508+
<SymbolView
509+
name="chevron.right"
510+
size={14}
511+
tintColorClassName="accent-chevron"
512+
type="monochrome"
513+
/>
514+
</Pressable>
515+
</View>
516+
)
517+
) : null}
381518
</ScrollView>
382519
</MaterialScreenContent>
383520
</View>

‎apps/server/src/ws.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,6 +1774,7 @@ const makeWsRpcLayer = (
17741774
);
17751775
const environment = yield* serverEnvironment.getDescriptor;
17761776
const auth = yield* serverAuth.getDescriptor();
1777+
const path = yield* Path.Path;
17771778
const availableEditors: ReadonlyArray<EditorId> = yield* resolveAvailableEditorsForConfig(
17781779
externalLauncher.resolveAvailableEditors(),
17791780
);
@@ -1820,6 +1821,7 @@ const makeWsRpcLayer = (
18201821
threadResumeCompletionMarker: true,
18211822
threadSnapshotPagination: true,
18221823
reasoningMessages: true,
1824+
chatWorkspaceRoot: path.join(config.baseDir, "chats"),
18231825
};
18241826
});
18251827

‎apps/web/src/components/CommandPalette.tsx‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import {
4747
FileSearchIcon,
4848
FolderIcon,
4949
FolderPlusIcon,
50+
MessageCircleIcon,
5051
LinkIcon,
5152
MessageSquareIcon,
5253
MonitorIcon,
@@ -95,6 +96,7 @@ import { useEnvironmentQuery } from "../state/query";
9596
import { sourceControlEnvironment } from "../state/sourceControl";
9697
import { useAtomCommand } from "../state/use-atom-command";
9798
import { useAtomQueryRunner } from "../state/use-atom-query-runner";
99+
import { useChatProject } from "../hooks/useChatProject";
98100
import { useEnvironments, usePrimaryEnvironmentId } from "../state/environments";
99101
import { useProjects, useServerConfigs, useThreadShells, waitForProject } from "../state/entities";
100102
import { useThreadSearch } from "../state/queries";
@@ -698,6 +700,7 @@ function OpenCommandPaletteDialog(props: {
698700
const createProject = useAtomCommand(projectEnvironment.create, {
699701
reportFailure: false,
700702
});
703+
const { chatWorkspaceRootFor, ensureChatProject } = useChatProject();
701704
const lookupRepository = useAtomQueryRunner(sourceControlEnvironment.repository, {
702705
reportFailure: false,
703706
});
@@ -1506,6 +1509,22 @@ function OpenCommandPaletteDialog(props: {
15061509
},
15071510
},
15081511
];
1512+
if (chatWorkspaceRootFor(environmentId) !== null) {
1513+
sourceItems.push({
1514+
kind: "action",
1515+
value: `action:add-project:${environmentId}:chat`,
1516+
searchTerms: ["chat", "no project", "without", "conversation"],
1517+
title: "Just chat",
1518+
description: "Start a thread without a repository",
1519+
icon: <MessageCircleIcon className={ITEM_ICON_CLASS} />,
1520+
run: async () => {
1521+
const projectRef = await ensureChatProject(environmentId);
1522+
if (projectRef) {
1523+
await handleNewThread(projectRef);
1524+
}
1525+
},
1526+
});
1527+
}
15091528

15101529
const orderedSources: ReadonlyArray<AddProjectRemoteSource> = [
15111530
"url",
@@ -1578,7 +1597,14 @@ function OpenCommandPaletteDialog(props: {
15781597

15791598
return [{ value: `sources:${environmentId}`, label: "Sources", items: sourceItems }];
15801599
},
1581-
[openSourceControlSettings, startAddProjectBrowse, startAddProjectClone],
1600+
[
1601+
chatWorkspaceRootFor,
1602+
ensureChatProject,
1603+
handleNewThread,
1604+
openSourceControlSettings,
1605+
startAddProjectBrowse,
1606+
startAddProjectClone,
1607+
],
15821608
);
15831609

15841610
const startAddProjectSourceSelection = useCallback(

‎apps/web/src/components/NoProjectsHero.tsx‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1-
import { PlusIcon } from "lucide-react";
1+
import { MessageCircleIcon, PlusIcon } from "lucide-react";
22
import { useCallback } from "react";
33

44
import { openCommandPalette } from "../commandPaletteBus";
5+
import { useChatProject } from "../hooks/useChatProject";
6+
import { useNewThreadHandler } from "../hooks/useHandleNewThread";
7+
import { usePrimaryEnvironmentId } from "../state/environments";
58
import { Button } from "./ui/button";
69
import { Empty, EmptyDescription, EmptyHeader, EmptyTitle } from "./ui/empty";
710
import { SidebarInset } from "./ui/sidebar";
811

912
export function NoProjectsHero() {
1013
const openAddProject = useCallback(() => openCommandPalette({ open: "add-project" }), []);
14+
const primaryEnvironmentId = usePrimaryEnvironmentId();
15+
const { chatWorkspaceRootFor, ensureChatProject } = useChatProject();
16+
const handleNewThread = useNewThreadHandler();
17+
const canJustChat = chatWorkspaceRootFor(primaryEnvironmentId) !== null;
18+
const startChat = useCallback(async () => {
19+
if (primaryEnvironmentId === null) return;
20+
const projectRef = await ensureChatProject(primaryEnvironmentId);
21+
if (projectRef) await handleNewThread(projectRef);
22+
}, [ensureChatProject, handleNewThread, primaryEnvironmentId]);
1123

1224
return (
1325
<SidebarInset className="h-dvh min-h-0 overflow-hidden overscroll-y-none bg-background text-foreground">
@@ -21,11 +33,17 @@ export function NoProjectsHero() {
2133
<EmptyDescription className="mt-2 text-sm text-muted-foreground/78">
2234
Add a project to start your first thread.
2335
</EmptyDescription>
24-
<div className="mt-6 flex justify-center">
36+
<div className="mt-6 flex justify-center gap-2">
2537
<Button size="sm" onClick={openAddProject}>
2638
<PlusIcon className="size-4" />
2739
Add project
2840
</Button>
41+
{canJustChat ? (
42+
<Button size="sm" variant="outline" onClick={() => void startChat()}>
43+
<MessageCircleIcon className="size-4" />
44+
Just chat
45+
</Button>
46+
) : null}
2947
</div>
3048
</EmptyHeader>
3149
</div>

0 commit comments

Comments
 (0)