@5h0ov/paseo-quick-chat 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Shuvadipta Das
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/OVERVIEW.md ADDED
@@ -0,0 +1,28 @@
1
+ Quick Chat lets you talk to an agent without choosing a project first. When a chat turns into work on a codebase, you can connect it to a project and the conversation carries on there.
2
+
3
+ ## How it works
4
+
5
+ Clicking **Quick chats** in the sidebar opens a workspace in Paseo's own chat view, with the usual provider and model picker. Paseo agents always run in a folder, so quick chats run in a scratch folder in Paseo's data directory (`~/.paseo/quick-chat`). That workspace is hidden from the sidebar's project list.
6
+
7
+ Agents started there get a short system note saying there's no project, so they answer directly instead of looking for code.
8
+
9
+ **Connect to project**, in a chat's message box or the command center, starts a new agent in the project you pick (or a folder you search for, which is added as a project) and gives it the chat's transcript as its first message. The new agent uses the provider's default mode, so the project's usual permission prompts apply. By default the original chat is then archived.
10
+
11
+ ## Setup
12
+
13
+ Requires Paseo 0.13 or later and at least one agent provider (Claude Code, Codex, OpenCode or another) on the host. Tested on Windows.
14
+
15
+ Preferences:
16
+
17
+ - Archive a chat after connecting it to a project (on by default).
18
+ - Tell chats there's no project (on by default).
19
+
20
+ ## Data
21
+
22
+ Chats go to the agent provider you pick, like any Paseo agent. Connecting a chat sends its transcript (your messages, the replies, and one line per tool call) to the provider of the new agent in the project. Quick Chat stores nothing else; it labels the agents it creates in projects with the chat they came from.
23
+
24
+ ## Limitations
25
+
26
+ - The agent in the project gets the chat as text, not the original session, so tool output and reasoning aren't carried over.
27
+ - Files a chat wrote stay in the scratch folder, not in the project.
28
+ - Other plugins that don't look in hidden workspaces can miss quick chats. The README lists known cases.
package/README.md CHANGED
@@ -1,3 +1,93 @@
1
- # Temporary Holding Version
1
+ # Quick Chat
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Talk to an agent in [Paseo](https://paseo.sh) without picking a project first, and connect the chat to a project later if it turns into real work.
4
+
5
+ - **Chat right away.** Click **Quick chats** in the sidebar and you're in Paseo's own new-chat tab, with its usual provider and model picker. No folder to choose.
6
+ - **All your chats in one place.** They're the agents in the **Quick chats** workspace, listed in the sidebar like any other.
7
+ - **Connect to a project later.** A **Connect to project** button in each chat's message box (or **Connect this chat to a project** in the command center, Ctrl+K / ⌘K) carries the conversation over to an agent in the project you pick. Search your open projects, or any folder on the computer, on any drive.
8
+ - **Works on your phone.** Everything works from Paseo's mobile app too.
9
+
10
+ ## Install
11
+
12
+ Requirements:
13
+
14
+ - Paseo 0.13 or later, with plugins enabled (**Settings → Plugins → Enable plugins**).
15
+ - At least one agent provider (Claude Code, Codex, OpenCode, …) installed where the daemon runs.
16
+
17
+ In the app, open **Settings → Plugins**, paste `npm:@5h0ov/paseo-quick-chat` as the plugin source, and install. Or, on the daemon host:
18
+
19
+ ```bash
20
+ paseo plugin install npm:@5h0ov/paseo-quick-chat
21
+ # or straight from GitHub:
22
+ paseo plugin install github:5h0ov/paseo-quick-chat
23
+ ```
24
+
25
+ Then open **Quick chats** in the sidebar.
26
+
27
+ ## Use it
28
+
29
+ 1. Click **Quick chats** in the sidebar, or **New quick chat** in the command center (Ctrl+K / ⌘K). The first time, this sets up the **Quick chats** workspace.
30
+ 2. Start a chat in Paseo's new-chat tab as usual.
31
+ 3. When a chat turns into work on a codebase, press **Connect to project** in its message box and pick a project, or search for a folder (it's added as a project). Arrow keys and Enter work too. A new agent starts there with the conversation so far, and you're taken to it.
32
+
33
+ **Open Preferences** (Settings → Plugins → quick-chat → ⋯):
34
+
35
+ - **Archive chats once connected** (on by default).
36
+ - **Tell chats there's no project**, so they answer directly instead of looking for code (on by default).
37
+
38
+ ## How it works
39
+
40
+ Every Paseo agent runs in a folder, so quick chats run in a scratch folder, `~/.paseo/quick-chat`, registered once as a workspace called **Quick chats**. Any agent started there counts as a quick chat, and gets a short system prompt saying there's no project (added by an `agent.create` hook, whichever provider you pick).
41
+
42
+ An agent can't change folders, so connecting a chat starts a new agent in the project instead. Its first message is the chat's transcript: your messages and the replies, plus one line per tool call. A long chat keeps its first message and its most recent part. The new agent starts in the provider's default mode, not the chat's, so the project gets its usual permission prompts.
43
+
44
+ ## Privacy and safety
45
+
46
+ - Nothing leaves your machine except what your agent provider already sends. Quick Chat keeps no data of its own beyond the scratch folder and a label on agents it creates in projects (`quick-chat.connected-from`). Folder search lists folder names on the daemon host in memory, for the picker only; nothing is saved or sent.
47
+ - Connecting a chat never changes files in the project. The new agent only acts on what you ask next.
48
+
49
+ ## Limitations
50
+
51
+ - The new agent in the project gets the chat as text, not the original session: tool output and reasoning aren't carried over.
52
+ - Files a chat wrote are in the scratch folder, not in the project. The hand-off message says so.
53
+ - Tested on Windows with Paseo 0.13.
54
+
55
+ ## Development
56
+
57
+ ```bash
58
+ git clone https://github.com/5h0ov/paseo-quick-chat.git
59
+ cd paseo-quick-chat
60
+ bun install
61
+ paseo plugin install "$(pwd)" # run the working copy
62
+
63
+ bun run typecheck # client and server, separately
64
+ bun run test # chats, connecting, client bundle and mobile checks
65
+ paseo plugin reload quick-chat
66
+ paseo plugin logs quick-chat
67
+ ```
68
+
69
+ Code layout:
70
+
71
+ - `client/`: React Native UI (opening the workspace, project picker, composer pill, settings).
72
+ - `server/`: chat creation, the scratch workspace, connecting chats to projects, folder search (`folders.ts`).
73
+ - `shared/`: RPC contracts.
74
+
75
+ See [CONTRIBUTING.md](CONTRIBUTING.md). Report problems at [github.com/5h0ov/paseo-quick-chat/issues](https://github.com/5h0ov/paseo-quick-chat/issues).
76
+
77
+ ## Uninstall
78
+
79
+ ```bash
80
+ paseo plugin remove quick-chat
81
+ ```
82
+
83
+ Your chats stay in Paseo under the **Quick chats** workspace; archive it if you don't want them. The scratch folder is `~/.paseo/quick-chat`.
84
+
85
+ ## Compatibility with other plugins
86
+
87
+ Quick chats live in a hidden (background) workspace, which keeps the scratch folder out of the sidebar's project list. Paseo leaves agents in hidden workspaces out of the agent lists plugins get unless a plugin asks for them, so plugins that don't can miss quick chats. Known cases, updated as more are found:
88
+
89
+ | Plugin | What happens in quick chats | Workaround |
90
+ | --- | --- | --- |
91
+ | [ZeroSub](https://github.com/kapybara-org/zerosub) | The account pill in the message box doesn't show, so you can't switch account from a quick chat. Account routing still works: chats use your default account and switch when it hits a limit. | Switch accounts from a project chat or the Accounts screen. |
92
+
93
+ Found another? [Open an issue](https://github.com/5h0ov/paseo-quick-chat/issues).
@@ -0,0 +1,32 @@
1
+ import type { PluginClientContext } from "@getpaseo/plugin/client";
2
+ import { openChats } from "../shared/rpc";
3
+
4
+ export interface ChatsLocation {
5
+ workspaceId: string;
6
+ directory: string;
7
+ }
8
+
9
+ /**
10
+ * The Quick chats workspace and folder, looked up once and shared. A failed lookup isn't
11
+ * remembered, so the next caller tries again.
12
+ */
13
+ export function chatsWorkspace(client: Pick<PluginClientContext, "rpc">): () => Promise<ChatsLocation> {
14
+ let pending: Promise<ChatsLocation> | null = null;
15
+ return () => {
16
+ pending ??= client.rpc(openChats, {}).catch((error: unknown) => {
17
+ pending = null;
18
+ throw error;
19
+ });
20
+ return pending;
21
+ };
22
+ }
23
+
24
+ /** Quick chats are the agents anywhere in the chats folder, whichever workspace they're in. */
25
+ export function isChat(cwd: string | null | undefined, directory: string): boolean {
26
+ if (!cwd) return false;
27
+ // Paseo runs on Windows too: compare without caring about separators or (there) case.
28
+ const norm = (value: string) => value.replace(/[\\/]+/g, "/").replace(/\/$/, "").toLowerCase();
29
+ const child = norm(cwd);
30
+ const root = norm(directory);
31
+ return child === root || child.startsWith(`${root}/`);
32
+ }
@@ -0,0 +1,47 @@
1
+ import type { PluginClientContext, PluginSurfaceProps } from "@getpaseo/plugin/client";
2
+ import { useCallback, useEffect, useState } from "react";
3
+ import { ActivityIndicator, Text, View } from "react-native";
4
+ import { openChats } from "../shared/rpc";
5
+ import { Button, describe, useText } from "./ui";
6
+
7
+ type Rpc = PluginClientContext["rpc"];
8
+
9
+ /**
10
+ * The sidebar entry: sets up the Quick chats workspace if needed, then hands over to Paseo's own
11
+ * workspace view, so chats use the native new-agent tab and chat UI.
12
+ */
13
+ export function OpenChats({ theme, navigation, rpc }: PluginSurfaceProps & { rpc: Rpc }) {
14
+ const text = useText(theme);
15
+ const [error, setError] = useState<string | null>(null);
16
+
17
+ const open = useCallback(async () => {
18
+ setError(null);
19
+ try {
20
+ const { workspaceId } = await rpc(openChats, {});
21
+ if (navigation) navigation.openWorkspace({ workspaceId });
22
+ else setError("This Paseo can't open it from here.");
23
+ } catch (failure) {
24
+ setError(describe(failure));
25
+ }
26
+ }, [rpc, navigation]);
27
+
28
+ useEffect(() => {
29
+ void open();
30
+ }, [open]);
31
+
32
+ return (
33
+ <View style={{ flex: 1, alignItems: "center", justifyContent: "center", gap: 12, padding: 24, backgroundColor: theme.colors.surface0 }}>
34
+ {error ? (
35
+ <>
36
+ <Text style={[text.danger, { textAlign: "center" }]}>Couldn't open Quick chats: {error}</Text>
37
+ <Button theme={theme} label="Try again" onPress={() => void open()} />
38
+ </>
39
+ ) : (
40
+ <>
41
+ <ActivityIndicator color={theme.colors.foregroundMuted} />
42
+ <Text style={text.muted}>Opening Quick chats…</Text>
43
+ </>
44
+ )}
45
+ </View>
46
+ );
47
+ }
@@ -0,0 +1,130 @@
1
+ import type { PluginButtonContentProps, PluginButtonRegistration, PluginClientContext } from "@getpaseo/plugin/client";
2
+ import { View } from "react-native";
3
+ import { isChat, type ChatsLocation } from "./chats-workspace";
4
+ import { ProjectPicker } from "./project-picker";
5
+ import { OPEN_AGENT_SCREEN } from "./screens";
6
+
7
+ const PAGE_SIZE = 200;
8
+ const MAX_PAGES = 10;
9
+
10
+ interface Agent {
11
+ id: string;
12
+ cwd: string;
13
+ workspaceId?: string | null;
14
+ archivedAt?: string | null;
15
+ }
16
+
17
+ /**
18
+ * A "Connect to project" pill in the composer of every quick chat. Agents are watched through a
19
+ * list subscription: `agents.subscribe` alone gets no updates.
20
+ */
21
+ export function contributePills(client: PluginClientContext, chatsWorkspace: () => Promise<ChatsLocation>): () => void {
22
+ const chats = new Map<string, string>(); // agent → workspace
23
+ const pills = new Map<string, PluginButtonRegistration>();
24
+ const lifetime = new AbortController();
25
+ let directory: string | null = null;
26
+ let stopped = false;
27
+
28
+ function Content(props: PluginButtonContentProps) {
29
+ if (props.context !== "agent") return null;
30
+ const { theme, agentId, close } = props;
31
+ return (
32
+ <View style={{ width: 440, maxWidth: "100%" }}>
33
+ <ProjectPicker
34
+ theme={theme}
35
+ rpc={client.rpc}
36
+ agentId={agentId}
37
+ hostLabel={props.host.label}
38
+ compact={props.layout.compact}
39
+ onCancel={close}
40
+ onConnected={(id) => {
41
+ close();
42
+ client.openScreen({ screenId: OPEN_AGENT_SCREEN, params: { agentId: id } });
43
+ }}
44
+ />
45
+ </View>
46
+ );
47
+ }
48
+
49
+ const track = (agent: Agent) => {
50
+ if (directory && agent.workspaceId && !agent.archivedAt && isChat(agent.cwd, directory)) chats.set(agent.id, agent.workspaceId);
51
+ else chats.delete(agent.id);
52
+ };
53
+
54
+ function sync(): void {
55
+ if (stopped) return;
56
+ for (const [agentId, pill] of pills) {
57
+ if (chats.has(agentId)) continue;
58
+ pill.remove();
59
+ pills.delete(agentId);
60
+ }
61
+ for (const [agentId, workspaceId] of chats) {
62
+ if (pills.has(agentId)) continue;
63
+ try {
64
+ pills.set(
65
+ agentId,
66
+ client.addComposerPill({
67
+ id: "connect",
68
+ workspaceId,
69
+ agentId,
70
+ button: { title: "Continue this chat in a project", label: "Connect to project", icon: "FolderInput", behavior: { kind: "popover", Content } },
71
+ }),
72
+ );
73
+ } catch (error) {
74
+ console.warn("[Quick Chat] could not add the connect pill", error);
75
+ }
76
+ }
77
+ }
78
+
79
+ // The subscription covers the newest page and every later change; older chats come from the
80
+ // remaining pages, so a chat idle for a while still gets its pill.
81
+ const newestFirst = () => [{ key: "updated_at" as const, direction: "desc" as const }];
82
+ // The chats workspace is a background one, and Paseo leaves its agents out of lists by default.
83
+ const withChats = { filter: { includeBackground: true } };
84
+ let snapshots = 0;
85
+ async function loadOlder(cursor: string | null, generation: number): Promise<void> {
86
+ for (let page = 1; cursor && page < MAX_PAGES; page += 1) {
87
+ const result = await client.paseo.agents.list({ ...withChats, signal: lifetime.signal, sort: newestFirst(), page: { limit: PAGE_SIZE, cursor } });
88
+ if (stopped || generation !== snapshots) return;
89
+ for (const { agent } of result.entries) track(agent);
90
+ sync();
91
+ cursor = result.pageInfo.hasMore ? (result.pageInfo.nextCursor ?? null) : null;
92
+ }
93
+ }
94
+
95
+ void chatsWorkspace()
96
+ .then((location) => {
97
+ directory = location.directory;
98
+ return client.paseo.agents.list({ ...withChats, subscribe: {}, signal: lifetime.signal, sort: newestFirst(), page: { limit: PAGE_SIZE } });
99
+ })
100
+ .then(({ subscription }) => {
101
+ subscription.subscribe({
102
+ snapshot: ({ entries, pageInfo }) => {
103
+ const generation = ++snapshots;
104
+ chats.clear();
105
+ for (const { agent } of entries) track(agent);
106
+ sync();
107
+ void loadOlder(pageInfo.hasMore ? (pageInfo.nextCursor ?? null) : null, generation).catch((error: unknown) => {
108
+ if (!stopped) console.warn("[Quick Chat] could not list older agents", error);
109
+ });
110
+ },
111
+ update: (message) => {
112
+ if (message.type !== "agent_update") return;
113
+ const update = message.payload;
114
+ if (update.kind === "remove") chats.delete(update.agentId);
115
+ else track(update.agent);
116
+ sync();
117
+ },
118
+ });
119
+ })
120
+ .catch((error: unknown) => {
121
+ if (!stopped) console.error("[Quick Chat] watching chats failed", error);
122
+ });
123
+
124
+ return () => {
125
+ stopped = true;
126
+ lifetime.abort();
127
+ for (const pill of pills.values()) pill.remove();
128
+ pills.clear();
129
+ };
130
+ }
@@ -0,0 +1,301 @@
1
+ import type { PluginClientContext } from "@getpaseo/plugin/client";
2
+ import { Icon, ScrollView, TextInput, useToast } from "@getpaseo/plugin/client/ui";
3
+ import { useEffect, useMemo, useRef, useState } from "react";
4
+ import { ActivityIndicator, Platform, Pressable, Text, View } from "react-native";
5
+ import { connectChat, findFolders, listProjects, type ProjectChoice } from "../shared/rpc";
6
+ import { describe, type Theme } from "./ui";
7
+
8
+ type Rpc = PluginClientContext["rpc"];
9
+
10
+ const MAX_SHOWN = 30;
11
+ const SEARCH_DELAY_MS = 200;
12
+ // Short enough that header, search, list and key hints all fit in the composer popover, which
13
+ // otherwise scrolls as a whole and hides the hints.
14
+ const LIST_HEIGHT = 260;
15
+
16
+ interface Row {
17
+ key: string;
18
+ title: string;
19
+ subtitle: string;
20
+ icon: string;
21
+ target: { workspaceId: string } | { directory: string };
22
+ }
23
+
24
+ const baseName = (path: string) => path.replace(/[\\/]+$/, "").split(/[\\/]/).pop() || path;
25
+ /** Letters and digits only, lower case: spaces, "-", "_" and capitals don't matter. */
26
+ const squash = (text: string) => text.toLowerCase().replace(/[^\p{L}\p{N}]+/gu, "");
27
+ const samePath = (a: string, b: string) => a.replace(/[\\/]+$/, "").toLowerCase() === b.replace(/[\\/]+$/, "").toLowerCase();
28
+
29
+ /**
30
+ * Picks where a chat continues: an open project, or any folder on the host (added as a project
31
+ * first). Laid out like Paseo's own pickers: header with the host, search, rows, key hints.
32
+ */
33
+ export function ProjectPicker({
34
+ theme,
35
+ rpc,
36
+ agentId,
37
+ hostLabel,
38
+ compact,
39
+ onCancel,
40
+ onConnected,
41
+ maxShown = MAX_SHOWN,
42
+ }: {
43
+ theme: Theme;
44
+ rpc: Rpc;
45
+ agentId: string;
46
+ hostLabel?: string;
47
+ compact?: boolean;
48
+ onCancel?(): void;
49
+ onConnected(agentId: string): void;
50
+ maxShown?: number;
51
+ }) {
52
+ const colors = theme.colors;
53
+ const toast = useToast();
54
+ const [projects, setProjects] = useState<ProjectChoice[] | null>(null);
55
+ const [error, setError] = useState<string | null>(null);
56
+ const [query, setQuery] = useState("");
57
+ const [folders, setFolders] = useState<{ query: string; rows: Row[]; error: string | null } | null>(null);
58
+ const [highlight, setHighlight] = useState(0);
59
+ const [busy, setBusy] = useState<string | null>(null);
60
+ const input = useRef<{ focus(): void; isFocused?(): boolean } | null>(null);
61
+
62
+ // The popover moves focus to itself once it has opened (after its animation), so autoFocus, or one
63
+ // early focus(), loses. Keep focusing the search until it holds, for up to a second, so arrow keys
64
+ // reach it instead of moving focus between the popover's buttons.
65
+ useEffect(() => {
66
+ if (compact) return;
67
+ let tries = 0;
68
+ let held = 0;
69
+ const timer = setInterval(() => {
70
+ const field = input.current;
71
+ tries += 1;
72
+ if (field?.isFocused?.()) held += 1;
73
+ else {
74
+ held = 0;
75
+ field?.focus();
76
+ }
77
+ if (held >= 3 || tries >= 20) clearInterval(timer);
78
+ }, 50);
79
+ return () => clearInterval(timer);
80
+ }, [compact]);
81
+
82
+ useEffect(() => {
83
+ let live = true;
84
+ rpc(listProjects, {}).then(
85
+ (result) => live && setProjects(result.projects),
86
+ (failure: unknown) => live && setError(describe(failure)),
87
+ );
88
+ return () => {
89
+ live = false;
90
+ };
91
+ }, [rpc]);
92
+
93
+ // Folder search runs on the host, a moment after typing stops.
94
+ const needle = query.trim();
95
+ useEffect(() => {
96
+ if (!needle) return setFolders(null);
97
+ let live = true;
98
+ const timer = setTimeout(() => {
99
+ rpc(findFolders, { query: needle }).then(
100
+ (result) =>
101
+ live &&
102
+ setFolders({
103
+ query: needle,
104
+ error: result.error,
105
+ rows: result.folders.map((folder) => ({
106
+ key: `dir:${folder.directory}`,
107
+ title: baseName(folder.directory),
108
+ subtitle: folder.shortDirectory,
109
+ icon: "Folder",
110
+ target: { directory: folder.directory },
111
+ })),
112
+ }),
113
+ (failure: unknown) => live && setFolders({ query: needle, rows: [], error: describe(failure) }),
114
+ );
115
+ }, SEARCH_DELAY_MS);
116
+ return () => {
117
+ live = false;
118
+ clearTimeout(timer);
119
+ };
120
+ }, [rpc, needle]);
121
+
122
+ const { projectRows, folderRows } = useMemo(() => {
123
+ // As the folder search does: "rename me" finds rename-me-test, renameMe and rename_me.
124
+ const lower = squash(needle);
125
+ const matching = (projects ?? []).filter((p) => !lower || squash(p.label).includes(lower) || squash(p.directory).includes(lower));
126
+ const projectRows: Row[] = matching.slice(0, maxShown).map((p) => ({
127
+ key: p.workspaceId,
128
+ title: p.label,
129
+ subtitle: p.shortDirectory,
130
+ icon: p.worktree ? "GitBranch" : "FolderOpen",
131
+ target: { workspaceId: p.workspaceId },
132
+ }));
133
+ // Folders that are already open projects are listed once, as the project.
134
+ const open = projects ?? [];
135
+ const folderRows = (folders?.rows ?? []).filter(
136
+ (row) => "directory" in row.target && !open.some((p) => samePath(p.directory, (row.target as { directory: string }).directory)),
137
+ );
138
+ return { projectRows, folderRows };
139
+ }, [projects, folders, needle, maxShown]);
140
+
141
+ const rows = [...projectRows, ...folderRows];
142
+ useEffect(() => setHighlight(0), [needle]);
143
+
144
+ const connect = async (row: Row) => {
145
+ if (busy) return;
146
+ setBusy(row.key);
147
+ try {
148
+ const result = await rpc(connectChat, { agentId, ...row.target });
149
+ onConnected(result.agentId);
150
+ } catch (failure) {
151
+ toast.show(describe(failure), { variant: "error" });
152
+ setBusy(null);
153
+ }
154
+ };
155
+
156
+ // The list scrolls on its own, so the row picked with the arrow keys can be kept in view.
157
+ const list = useRef<{ scrollTo(options: { y: number; animated?: boolean }): void } | null>(null);
158
+ const rowFrames = useRef(new Map<number, { y: number; height: number }>());
159
+ const scrollY = useRef(0);
160
+ const viewHeight = useRef(LIST_HEIGHT);
161
+ useEffect(() => {
162
+ const frame = rowFrames.current.get(highlight);
163
+ if (!frame) return;
164
+ // The section label above the first row of each group comes along when scrolling up.
165
+ const top = frame.y - 24;
166
+ const bottom = frame.y + frame.height;
167
+ if (top < scrollY.current) list.current?.scrollTo({ y: Math.max(0, top), animated: false });
168
+ else if (bottom > scrollY.current + viewHeight.current) list.current?.scrollTo({ y: bottom - viewHeight.current, animated: false });
169
+ }, [highlight]);
170
+
171
+ const onKey = (event: { nativeEvent: { key: string }; preventDefault?(): void; stopPropagation?(): void }) => {
172
+ const key = event.nativeEvent.key;
173
+ if (key === "ArrowDown" || key === "ArrowUp") {
174
+ event.preventDefault?.();
175
+ event.stopPropagation?.();
176
+ if (rows.length) setHighlight((at) => (at + (key === "ArrowDown" ? 1 : rows.length - 1)) % rows.length);
177
+ } else if (key === "Enter") {
178
+ const row = rows[highlight];
179
+ if (row) void connect(row);
180
+ } else if (key === "Escape") onCancel?.();
181
+ };
182
+
183
+ const divider = { height: 1, backgroundColor: colors.border };
184
+ const muted = { color: colors.foregroundMuted, fontSize: 12 };
185
+ const showHints = Platform.OS === "web" && !compact;
186
+
187
+ const section = (label: string) => (
188
+ <Text style={{ ...muted, fontSize: 11, fontWeight: "600", paddingHorizontal: 14, paddingTop: 8, paddingBottom: 4 }}>{label}</Text>
189
+ );
190
+
191
+ const renderRow = (row: Row, index: number) => {
192
+ const active = index === highlight;
193
+ return (
194
+ <Pressable
195
+ key={row.key}
196
+ accessibilityRole="button"
197
+ accessibilityLabel={`Continue in ${row.title}`}
198
+ accessibilityHint="A new agent there continues this chat"
199
+ disabled={busy !== null}
200
+ onPress={() => void connect(row)}
201
+ onHoverIn={() => setHighlight(index)}
202
+ onLayout={(event) => rowFrames.current.set(index, event.nativeEvent.layout)}
203
+ style={({ pressed }) => ({
204
+ flexDirection: "row",
205
+ alignItems: "center",
206
+ gap: 12,
207
+ paddingHorizontal: 14,
208
+ paddingVertical: 8,
209
+ backgroundColor: active || pressed ? colors.surface2 : "transparent",
210
+ opacity: busy && busy !== row.key ? 0.5 : 1,
211
+ })}
212
+ >
213
+ <Icon name={row.icon} size={16} color={colors.foregroundMuted} />
214
+ <View style={{ flex: 1, minWidth: 0 }}>
215
+ <Text style={{ color: colors.foreground, fontSize: 14 }} numberOfLines={1}>
216
+ {row.title}
217
+ </Text>
218
+ <Text style={muted} numberOfLines={1}>
219
+ {row.subtitle}
220
+ </Text>
221
+ </View>
222
+ {busy === row.key ? <ActivityIndicator size="small" color={colors.foregroundMuted} /> : null}
223
+ </Pressable>
224
+ );
225
+ };
226
+
227
+ const hint = (keys: string, label: string) => (
228
+ <View style={{ flexDirection: "row", alignItems: "center", gap: 6 }}>
229
+ <View style={{ backgroundColor: colors.surface2, borderRadius: 4, paddingHorizontal: 5, paddingVertical: 1 }}>
230
+ <Text style={{ color: colors.foreground, fontSize: 11 }}>{keys}</Text>
231
+ </View>
232
+ <Text style={muted}>{label}</Text>
233
+ </View>
234
+ );
235
+
236
+ let body;
237
+ if (error) body = <Text style={{ color: colors.statusDanger, fontSize: 13, padding: 14 }}>Couldn't list projects: {error}</Text>;
238
+ else if (projects === null) body = <Text style={{ ...muted, padding: 14 }}>Loading projects…</Text>;
239
+ else
240
+ body = (
241
+ <ScrollView
242
+ ref={list as never}
243
+ style={{ maxHeight: LIST_HEIGHT }}
244
+ contentContainerStyle={{ paddingVertical: 4 }}
245
+ keyboardShouldPersistTaps="handled"
246
+ scrollEventThrottle={16}
247
+ onScroll={(event) => (scrollY.current = event.nativeEvent.contentOffset.y)}
248
+ onLayout={(event) => (viewHeight.current = event.nativeEvent.layout.height)}
249
+ >
250
+ {projectRows.length ? section("Projects") : null}
251
+ {projectRows.map((row, i) => renderRow(row, i))}
252
+ {folderRows.length ? section(`Folders on ${hostLabel ?? "this host"}`) : null}
253
+ {folderRows.map((row, i) => renderRow(row, projectRows.length + i))}
254
+ {rows.length === 0 ? (
255
+ <Text style={{ ...muted, fontSize: 13, paddingHorizontal: 14, paddingVertical: 10 }}>
256
+ {!needle
257
+ ? "No projects yet. Search for a folder."
258
+ : folders?.query !== needle
259
+ ? "Searching…"
260
+ : folders.error
261
+ ? `No project matches. Folder search isn't available: ${folders.error}`
262
+ : `Nothing matches “${needle}”.`}
263
+ </Text>
264
+ ) : null}
265
+ </ScrollView>
266
+ );
267
+
268
+ return (
269
+ <View>
270
+ <View style={{ flexDirection: "row", alignItems: "baseline", gap: 8, paddingHorizontal: 14, paddingTop: 4, paddingBottom: 10 }}>
271
+ <Text style={{ color: colors.foreground, fontSize: 13, fontWeight: "600" }}>Connect to project</Text>
272
+ {hostLabel ? <Text style={muted}>{hostLabel}</Text> : null}
273
+ </View>
274
+ <TextInput
275
+ value={query}
276
+ onChangeText={setQuery}
277
+ onKeyPress={onKey}
278
+ onSubmitEditing={() => rows[highlight] && void connect(rows[highlight]!)}
279
+ ref={input as never}
280
+ placeholder="Search projects and folders…"
281
+ placeholderTextColor={colors.foregroundMuted}
282
+ autoCapitalize="none"
283
+ autoCorrect={false}
284
+ accessibilityLabel="Search projects and folders"
285
+ style={{ color: colors.foreground, fontSize: 14, paddingHorizontal: 14, paddingVertical: 10, borderTopWidth: 1, borderColor: colors.border, outlineStyle: "none" } as never}
286
+ />
287
+ <View style={divider} />
288
+ {body}
289
+ {showHints ? (
290
+ <>
291
+ <View style={divider} />
292
+ <View style={{ flexDirection: "row", gap: 16, paddingHorizontal: 14, paddingVertical: 8 }}>
293
+ {hint("↑↓", "Navigate")}
294
+ {hint("↵", "Connect")}
295
+ {onCancel ? hint("Esc", "Close") : null}
296
+ </View>
297
+ </>
298
+ ) : null}
299
+ </View>
300
+ );
301
+ }