@5h0ov/paseo-quick-chat 0.1.0 → 0.2.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/OVERVIEW.md CHANGED
@@ -10,7 +10,7 @@ Agents started there get a short system note saying there's no project, so they
10
10
 
11
11
  ## Setup
12
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.
13
+ Requires Paseo 0.15 or later and at least one agent provider (Claude Code, Codex, OpenCode or another) on the host. Tested on Windows.
14
14
 
15
15
  Preferences:
16
16
 
package/README.md CHANGED
@@ -11,7 +11,7 @@ Talk to an agent in [Paseo](https://paseo.sh) without picking a project first, a
11
11
 
12
12
  Requirements:
13
13
 
14
- - Paseo 0.13 or later, with plugins enabled (**Settings → Plugins → Enable plugins**).
14
+ - Paseo 0.15 or later, with plugins enabled (**Settings → Plugins → Enable plugins**).
15
15
  - At least one agent provider (Claude Code, Codex, OpenCode, …) installed where the daemon runs.
16
16
 
17
17
  In the app, open **Settings → Plugins**, paste `npm:@5h0ov/paseo-quick-chat` as the plugin source, and install. Or, on the daemon host:
@@ -30,7 +30,7 @@ Then open **Quick chats** in the sidebar.
30
30
  2. Start a chat in Paseo's new-chat tab as usual.
31
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
32
 
33
- **Open Preferences** (Settings → Plugins → quick-chat → ⋯):
33
+ **Open Preferences** (Settings → Plugins → quick-chat → the ⚙ button; ⋯ before Paseo 0.16):
34
34
 
35
35
  - **Archive chats once connected** (on by default).
36
36
  - **Tell chats there's no project**, so they answer directly instead of looking for code (on by default).
@@ -50,7 +50,7 @@ An agent can't change folders, so connecting a chat starts a new agent in the pr
50
50
 
51
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
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.
53
+ - Tested on Windows with Paseo 0.16.
54
54
 
55
55
  ## Development
56
56
 
@@ -1,55 +1,55 @@
1
- import type { PluginClientContext, PluginScreenProps } from "@getpaseo/plugin/client";
2
- import { ScrollView } from "@getpaseo/plugin/client/ui";
3
- import { useEffect } from "react";
4
- import { Text, View } from "react-native";
5
- import { ProjectPicker } from "./project-picker";
6
- import { useText } from "./ui";
7
-
8
- type Rpc = PluginClientContext["rpc"];
9
-
10
- export const CHATS_SCREEN = "chats";
11
- export const OPEN_AGENT_SCREEN = "open-agent";
12
- export const CONNECT_SCREEN = "connect";
13
-
14
- /** Popovers and commands can't navigate, but a screen can: this one just forwards to the agent. */
15
- export function OpenAgentScreen({ theme, params, navigation }: PluginScreenProps) {
16
- const text = useText(theme);
17
- const agentId = params.agentId;
18
- useEffect(() => {
19
- if (agentId) navigation?.openAgent({ agentId });
20
- }, [agentId, navigation]);
21
- return (
22
- <View style={{ padding: 20 }}>
23
- <Text style={text.muted}>{agentId ? "Opening the agent…" : "Nothing to open."}</Text>
24
- </View>
25
- );
26
- }
27
-
28
- export function ConnectScreen({ theme, layout, host, params, navigation, rpc }: PluginScreenProps & { rpc: Rpc }) {
29
- const text = useText(theme);
30
- const agentId = params.agentId;
31
- return (
32
- <View style={{ flex: 1, backgroundColor: theme.colors.surface0 }}>
33
- <ScrollView
34
- keyboardShouldPersistTaps="handled"
35
- contentContainerStyle={{ padding: layout.compact ? 16 : 24, gap: 12, maxWidth: 760, width: "100%", alignSelf: "center" }}
36
- >
37
- <Text style={text.title}>Connect chat to a project</Text>
38
- {agentId ? (
39
- <View style={{ borderWidth: 1, borderColor: theme.colors.border, borderRadius: 12, overflow: "hidden", backgroundColor: theme.colors.surface1 }}>
40
- <ProjectPicker
41
- theme={theme}
42
- rpc={rpc}
43
- agentId={agentId}
44
- hostLabel={host.label}
45
- compact={layout.compact}
46
- onConnected={(id) => navigation?.openAgent({ agentId: id })}
47
- />
48
- </View>
49
- ) : (
50
- <Text style={text.muted}>Open this from a quick chat.</Text>
51
- )}
52
- </ScrollView>
53
- </View>
54
- );
55
- }
1
+ import type { PluginClientContext, PluginScreenProps } from "@getpaseo/plugin/client";
2
+ import { ScrollView } from "@getpaseo/plugin/client/ui";
3
+ import { useEffect } from "react";
4
+ import { Text, View } from "react-native";
5
+ import { ProjectPicker } from "./project-picker";
6
+ import { useText } from "./ui";
7
+
8
+ type Rpc = PluginClientContext["rpc"];
9
+
10
+ export const CHATS_SCREEN = "chats";
11
+ export const OPEN_AGENT_SCREEN = "open-agent";
12
+ export const CONNECT_SCREEN = "connect";
13
+
14
+ /** Popovers and commands can't navigate, but a screen can: this one just forwards to the agent. */
15
+ export function OpenAgentScreen({ theme, params, navigation }: PluginScreenProps) {
16
+ const text = useText(theme);
17
+ const agentId = params.agentId;
18
+ useEffect(() => {
19
+ if (agentId) navigation?.openAgent({ agentId });
20
+ }, [agentId, navigation]);
21
+ return (
22
+ <View style={{ padding: 20 }}>
23
+ <Text style={text.muted}>{agentId ? "Opening the agent…" : "Nothing to open."}</Text>
24
+ </View>
25
+ );
26
+ }
27
+
28
+ export function ConnectScreen({ theme, layout, host, params, navigation, rpc }: PluginScreenProps & { rpc: Rpc }) {
29
+ const text = useText(theme);
30
+ const agentId = params.agentId;
31
+ return (
32
+ <View style={{ flex: 1, backgroundColor: theme.colors.surface0 }}>
33
+ <ScrollView
34
+ keyboardShouldPersistTaps="handled"
35
+ contentContainerStyle={{ padding: layout.compact ? 16 : 24, gap: 12, maxWidth: 760, width: "100%", alignSelf: "center" }}
36
+ >
37
+ <Text style={text.title}>Connect chat to a project</Text>
38
+ {agentId ? (
39
+ <View style={{ borderWidth: 1, borderColor: theme.colors.border, borderRadius: 12, overflow: "hidden", backgroundColor: theme.colors.surface1 }}>
40
+ <ProjectPicker
41
+ theme={theme}
42
+ rpc={rpc}
43
+ agentId={agentId}
44
+ hostLabel={host.label}
45
+ compact={layout.compact}
46
+ onConnected={(id) => navigation?.openAgent({ agentId: id })}
47
+ />
48
+ </View>
49
+ ) : (
50
+ <Text style={text.muted}>Open this from a quick chat.</Text>
51
+ )}
52
+ </ScrollView>
53
+ </View>
54
+ );
55
+ }
@@ -1,46 +1,46 @@
1
- import { useSettings, type PluginSurfaceProps } from "@getpaseo/plugin/client";
2
- import { SettingsAction, SettingsCard, SettingsSection, SettingsSwitch } from "@getpaseo/plugin/client/ui";
3
- import { Text, View } from "react-native";
4
- import { preferences } from "../shared/preferences";
5
- import { useText } from "./ui";
6
-
7
- export function SettingsScreen({ theme }: PluginSurfaceProps) {
8
- const text = useText(theme);
9
- const settings = useSettings(preferences);
10
- if (settings.status === "loading") return <Text style={text.muted}>Loading…</Text>;
11
- if (settings.status !== "ready") {
12
- return (
13
- <View style={{ gap: 8 }}>
14
- <Text style={text.danger}>{settings.error}</Text>
15
- <SettingsAction label="Try again" actionLabel="Reload" onPress={() => void settings.reload()} />
16
- {settings.status === "invalid" ? (
17
- <SettingsAction label="Restore defaults" actionLabel="Reset" onPress={() => void settings.reset()} />
18
- ) : null}
19
- </View>
20
- );
21
- }
22
- const { values, revision } = settings;
23
- const save = (patch: Partial<typeof values>) => void settings.save({ ...values, ...patch }, revision);
24
-
25
- return (
26
- <SettingsSection title="Quick Chat">
27
- <SettingsCard>
28
- <SettingsSwitch
29
- label="Archive chats once connected"
30
- hint="So a chat isn't in two places. You can still open archived chats."
31
- value={values.archiveAfterConnect}
32
- onValueChange={(archiveAfterConnect) => save({ archiveAfterConnect })}
33
- disabled={settings.saving}
34
- />
35
- <SettingsSwitch
36
- label="Tell chats there's no project"
37
- hint="So new chats answer directly instead of looking for code."
38
- value={values.noProjectNote}
39
- onValueChange={(noProjectNote) => save({ noProjectNote })}
40
- disabled={settings.saving}
41
- />
42
- </SettingsCard>
43
- {settings.saveError ? <Text style={text.danger}>{settings.saveError}</Text> : null}
44
- </SettingsSection>
45
- );
46
- }
1
+ import { useSettings, type PluginSurfaceProps } from "@getpaseo/plugin/client";
2
+ import { SettingsAction, SettingsCard, SettingsSection, SettingsSwitch } from "@getpaseo/plugin/client/ui";
3
+ import { Text, View } from "react-native";
4
+ import { preferences } from "../shared/preferences";
5
+ import { useText } from "./ui";
6
+
7
+ export function SettingsScreen({ theme }: PluginSurfaceProps) {
8
+ const text = useText(theme);
9
+ const settings = useSettings(preferences);
10
+ if (settings.status === "loading") return <Text style={text.muted}>Loading…</Text>;
11
+ if (settings.status !== "ready") {
12
+ return (
13
+ <View style={{ gap: 8 }}>
14
+ <Text style={text.danger}>{settings.error}</Text>
15
+ <SettingsAction label="Try again" actionLabel="Reload" onPress={() => void settings.reload()} />
16
+ {settings.status === "invalid" ? (
17
+ <SettingsAction label="Restore defaults" actionLabel="Reset" onPress={() => void settings.reset()} />
18
+ ) : null}
19
+ </View>
20
+ );
21
+ }
22
+ const { values, revision } = settings;
23
+ const save = (patch: Partial<typeof values>) => void settings.save({ ...values, ...patch }, revision);
24
+
25
+ return (
26
+ <SettingsSection title="Quick Chat">
27
+ <SettingsCard>
28
+ <SettingsSwitch
29
+ label="Archive chats once connected"
30
+ hint="So a chat isn't in two places. You can still open archived chats."
31
+ value={values.archiveAfterConnect}
32
+ onValueChange={(archiveAfterConnect) => save({ archiveAfterConnect })}
33
+ disabled={settings.saving}
34
+ />
35
+ <SettingsSwitch
36
+ label="Tell chats there's no project"
37
+ hint="So new chats answer directly instead of looking for code."
38
+ value={values.noProjectNote}
39
+ onValueChange={(noProjectNote) => save({ noProjectNote })}
40
+ disabled={settings.saving}
41
+ />
42
+ </SettingsCard>
43
+ {settings.saveError ? <Text style={text.danger}>{settings.saveError}</Text> : null}
44
+ </SettingsSection>
45
+ );
46
+ }
package/index.client.tsx CHANGED
@@ -1,59 +1,59 @@
1
- import type { PluginClientContext } from "@getpaseo/plugin/client";
2
- import { SidebarRow } from "@getpaseo/plugin/client/ui";
3
- import { chatsWorkspace, isChat } from "./client/chats-workspace";
4
- import { OpenChats } from "./client/open-chats";
5
- import { contributePills } from "./client/pills";
6
- import { CHATS_SCREEN, CONNECT_SCREEN, ConnectScreen, OPEN_AGENT_SCREEN, OpenAgentScreen } from "./client/screens";
7
- import { SettingsScreen } from "./client/settings-screen";
8
-
9
- export default function contribute(client: PluginClientContext) {
10
- const workspace = chatsWorkspace(client);
11
- const cleanups = [
12
- client.addScreen({ id: CHATS_SCREEN, title: "Quick chats", Component: (props) => <OpenChats {...props} rpc={client.rpc} /> }),
13
- client.addSidebarHeaderItem({
14
- id: "chats",
15
- title: "Quick chats",
16
- Component: ({ openScreen, currentScreen }) => (
17
- <SidebarRow
18
- icon="MessagesSquare"
19
- active={currentScreen?.screenId === CHATS_SCREEN}
20
- onPress={() => openScreen({ screenId: CHATS_SCREEN })}
21
- />
22
- ),
23
- }),
24
- client.addSettingsScreen({ id: "preferences", title: "Open Preferences", icon: "MessagesSquare", Component: SettingsScreen }),
25
- client.addScreen({ id: OPEN_AGENT_SCREEN, title: "Opening…", Component: OpenAgentScreen }),
26
- client.addScreen({
27
- id: CONNECT_SCREEN,
28
- title: "Connect chat to a project",
29
- Component: (props) => <ConnectScreen {...props} rpc={client.rpc} />,
30
- }),
31
- client.addCommandCenterItem({
32
- id: "new-chat",
33
- context: "global",
34
- title: "New quick chat",
35
- icon: "MessageSquarePlus",
36
- keywords: ["chat", "ask", "scratch", "general", "no project"],
37
- onSelect: (context) => context.openScreen({ screenId: CHATS_SCREEN }),
38
- }),
39
- client.addCommandCenterItem({
40
- id: "connect-chat",
41
- context: "agent",
42
- title: "Connect this chat to a project",
43
- icon: "FolderInput",
44
- keywords: ["quick chat", "move", "project"],
45
- onSelect: async (context) => {
46
- const chats = await workspace().catch(() => null);
47
- if (chats && isChat(context.agent.cwd, chats.directory)) {
48
- context.openScreen({ screenId: CONNECT_SCREEN, params: { agentId: context.agent.id } });
49
- } else {
50
- context.openScreen({ screenId: CHATS_SCREEN });
51
- }
52
- },
53
- }),
54
- contributePills(client, workspace),
55
- ];
56
- return () => {
57
- for (const cleanup of cleanups.reverse()) cleanup();
58
- };
59
- }
1
+ import type { PluginClientContext } from "@getpaseo/plugin/client";
2
+ import { SidebarRow } from "@getpaseo/plugin/client/ui";
3
+ import { chatsWorkspace, isChat } from "./client/chats-workspace";
4
+ import { OpenChats } from "./client/open-chats";
5
+ import { contributePills } from "./client/pills";
6
+ import { CHATS_SCREEN, CONNECT_SCREEN, ConnectScreen, OPEN_AGENT_SCREEN, OpenAgentScreen } from "./client/screens";
7
+ import { SettingsScreen } from "./client/settings-screen";
8
+
9
+ export default function contribute(client: PluginClientContext) {
10
+ const workspace = chatsWorkspace(client);
11
+ const cleanups = [
12
+ client.addScreen({ id: CHATS_SCREEN, title: "Quick chats", Component: (props) => <OpenChats {...props} rpc={client.rpc} /> }),
13
+ client.addSidebarHeaderItem({
14
+ id: "chats",
15
+ title: "Quick chats",
16
+ Component: ({ openScreen, currentScreen }) => (
17
+ <SidebarRow
18
+ icon="MessagesSquare"
19
+ active={currentScreen?.screenId === CHATS_SCREEN}
20
+ onPress={() => openScreen({ screenId: CHATS_SCREEN })}
21
+ />
22
+ ),
23
+ }),
24
+ client.addSettingsScreen({ id: "preferences", title: "Open Preferences", icon: "MessagesSquare", Component: SettingsScreen }),
25
+ client.addScreen({ id: OPEN_AGENT_SCREEN, title: "Opening…", Component: OpenAgentScreen }),
26
+ client.addScreen({
27
+ id: CONNECT_SCREEN,
28
+ title: "Connect chat to a project",
29
+ Component: (props) => <ConnectScreen {...props} rpc={client.rpc} />,
30
+ }),
31
+ client.addCommandCenterItem({
32
+ id: "new-chat",
33
+ context: "global",
34
+ title: "New quick chat",
35
+ icon: "MessageSquarePlus",
36
+ keywords: ["chat", "ask", "scratch", "general", "no project"],
37
+ onSelect: (context) => context.openScreen({ screenId: CHATS_SCREEN }),
38
+ }),
39
+ client.addCommandCenterItem({
40
+ id: "connect-chat",
41
+ context: "agent",
42
+ title: "Connect this chat to a project",
43
+ icon: "FolderInput",
44
+ keywords: ["quick chat", "move", "project"],
45
+ onSelect: async (context) => {
46
+ const chats = await workspace().catch(() => null);
47
+ if (chats && isChat(context.agent.cwd, chats.directory)) {
48
+ context.openScreen({ screenId: CONNECT_SCREEN, params: { agentId: context.agent.id } });
49
+ } else {
50
+ context.openScreen({ screenId: CHATS_SCREEN });
51
+ }
52
+ },
53
+ }),
54
+ contributePills(client, workspace),
55
+ ];
56
+ return () => {
57
+ for (const cleanup of cleanups.reverse()) cleanup();
58
+ };
59
+ }
package/index.server.ts CHANGED
@@ -1,52 +1,52 @@
1
- import type { PluginServerContext, PluginSettingsState } from "@getpaseo/plugin/server";
2
- import { Chats } from "./server/chats";
3
- import { preferences, type Preferences } from "./shared/preferences";
4
- import { folderSearch, shortPath } from "./server/folders";
5
- import { connectChat, findFolders, listProjects, openChats } from "./shared/rpc";
6
-
7
- export default function contribute(server: PluginServerContext) {
8
- const chats = new Chats();
9
- const folders = folderSearch();
10
-
11
- let current: Preferences = { archiveAfterConnect: true, noProjectNote: true };
12
- const settings = server.registerSettings(preferences);
13
- const apply = (state: PluginSettingsState<typeof preferences.schema>) => {
14
- if (state.status === "ready") current = state.values;
15
- };
16
- void settings.read().then(apply, (error: unknown) => console.error("[Quick Chat] could not read preferences", error));
17
- const stopSettings = settings.subscribe(apply);
18
-
19
- // Chats start in Paseo's own new-agent tab, so the "no project" note is added here, whatever
20
- // provider or model was picked.
21
- server.before("agent.create", ({ request }) => {
22
- if (!current.noProjectNote) return undefined;
23
- const config = chats.withSystemPrompt(request.config);
24
- return config ? { ...request, config } : undefined;
25
- });
26
-
27
- server.handle(openChats, async (_input, { paseo }) => ({ workspaceId: await chats.openWorkspace(paseo), directory: chats.directory }));
28
- server.handle(listProjects, async (_input, { paseo }) => {
29
- // The picker is opening: start listing folders, so its first search doesn't wait.
30
- folders.warm();
31
- return { projects: await chats.projects(paseo) };
32
- });
33
- server.handle(findFolders, async ({ query }) => {
34
- try {
35
- const found = await folders.find(query);
36
- return { folders: found.map((directory) => ({ directory, shortDirectory: shortPath(directory) })), error: null };
37
- } catch (error) {
38
- return { folders: [], error: error instanceof Error ? error.message : String(error) };
39
- }
40
- });
41
- server.handle(connectChat, async ({ agentId, workspaceId, directory, archiveOriginal }, { paseo }) => {
42
- // A folder that isn't a project yet is added as one first, as Paseo's "Add project" does.
43
- const target = workspaceId ?? (directory ? (await paseo.workspaces.open({ cwd: directory })).id : null);
44
- if (!target) throw new Error("Pick a project or folder.");
45
- return chats.connect(paseo, { agentId, workspaceId: target, archiveOriginal: archiveOriginal ?? current.archiveAfterConnect });
46
- });
47
-
48
- return () => {
49
- stopSettings();
50
- folders.close();
51
- };
52
- }
1
+ import type { PluginServerContext, PluginSettingsState } from "@getpaseo/plugin/server";
2
+ import { Chats } from "./server/chats";
3
+ import { preferences, type Preferences } from "./shared/preferences";
4
+ import { folderSearch, shortPath } from "./server/folders";
5
+ import { connectChat, findFolders, listProjects, openChats } from "./shared/rpc";
6
+
7
+ export default function contribute(server: PluginServerContext) {
8
+ const chats = new Chats();
9
+ const folders = folderSearch();
10
+
11
+ let current: Preferences = { archiveAfterConnect: true, noProjectNote: true };
12
+ const settings = server.registerSettings(preferences);
13
+ const apply = (state: PluginSettingsState<typeof preferences.schema>) => {
14
+ if (state.status === "ready") current = state.values;
15
+ };
16
+ void settings.read().then(apply, (error: unknown) => console.error("[Quick Chat] could not read preferences", error));
17
+ const stopSettings = settings.subscribe(apply);
18
+
19
+ // Chats start in Paseo's own new-agent tab, so the "no project" note is added here, whatever
20
+ // provider or model was picked.
21
+ server.addHook("agent.create.before", async ({ request }) => {
22
+ if (!current.noProjectNote) return undefined;
23
+ const config = chats.withSystemPrompt(request.config);
24
+ return config ? { ...request, config } : undefined;
25
+ });
26
+
27
+ server.handle(openChats, async (_input, { paseo }) => ({ workspaceId: await chats.openWorkspace(paseo), directory: chats.directory }));
28
+ server.handle(listProjects, async (_input, { paseo }) => {
29
+ // The picker is opening: start listing folders, so its first search doesn't wait.
30
+ folders.warm();
31
+ return { projects: await chats.projects(paseo) };
32
+ });
33
+ server.handle(findFolders, async ({ query }) => {
34
+ try {
35
+ const found = await folders.find(query);
36
+ return { folders: found.map((directory) => ({ directory, shortDirectory: shortPath(directory) })), error: null };
37
+ } catch (error) {
38
+ return { folders: [], error: error instanceof Error ? error.message : String(error) };
39
+ }
40
+ });
41
+ server.handle(connectChat, async ({ agentId, workspaceId, directory, archiveOriginal }, { paseo }) => {
42
+ // A folder that isn't a project yet is added as one first, as Paseo's "Add project" does.
43
+ const target = workspaceId ?? (directory ? (await paseo.workspaces.open({ cwd: directory })).id : null);
44
+ if (!target) throw new Error("Pick a project or folder.");
45
+ return chats.connect(paseo, { agentId, workspaceId: target, archiveOriginal: archiveOriginal ?? current.archiveAfterConnect });
46
+ });
47
+
48
+ return () => {
49
+ stopSettings();
50
+ folders.close();
51
+ };
52
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@5h0ov/paseo-quick-chat",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Chat with an agent without picking a project, and connect the chat to a project later.",
5
5
  "keywords": [
6
6
  "paseo",
@@ -38,9 +38,9 @@
38
38
  "test": "vitest run"
39
39
  },
40
40
  "devDependencies": {
41
- "@getpaseo/client": "^0.14.0",
42
- "@getpaseo/plugin": "^0.14.0",
43
- "@getpaseo/protocol": "^0.14.0",
41
+ "@getpaseo/client": "^0.16.2",
42
+ "@getpaseo/plugin": "^0.16.2",
43
+ "@getpaseo/protocol": "^0.16.2",
44
44
  "@types/node": "^22.20.4",
45
45
  "@types/react": "~19.2.0",
46
46
  "esbuild": "^0.28.2",
package/paseo-plugin.json CHANGED
@@ -1,12 +1,12 @@
1
- {
2
- "id": "quick-chat",
3
- "name": "Quick Chat",
4
- "description": "Chat with an agent without picking a project, and connect the chat to a project later.",
5
- "requirements": {
6
- "paseo": ">=0.13.0"
7
- },
8
- "media": [
9
- "images/1-chat.png",
10
- "images/2-connect.png"
11
- ]
12
- }
1
+ {
2
+ "id": "quick-chat",
3
+ "name": "Quick Chat",
4
+ "description": "Chat with an agent without picking a project, and connect the chat to a project later.",
5
+ "requirements": {
6
+ "paseo": ">=0.15.0"
7
+ },
8
+ "media": [
9
+ "images/1-chat.png",
10
+ "images/2-connect.png"
11
+ ]
12
+ }
package/server/chats.ts CHANGED
@@ -1,272 +1,272 @@
1
- import { mkdir } from "node:fs/promises";
2
- import { homedir } from "node:os";
3
- import path from "node:path";
4
- import type { PluginHandlerContext } from "@getpaseo/plugin/server";
5
- import type { ProjectChoice } from "../shared/rpc";
6
- import { buildTranscript, connectPrompt } from "./handoff";
7
- import { shortPath } from "./folders";
8
-
9
- export type PaseoApi = PluginHandlerContext["paseo"];
10
- type Agent = Awaited<ReturnType<PaseoApi["agents"]["list"]>>["entries"][number]["agent"];
11
- type Workspace = Awaited<ReturnType<PaseoApi["workspaces"]["list"]>>["entries"][number];
12
-
13
- /** On the agent a chat was carried over into: the chat it came from. */
14
- export const CONNECTED_FROM_LABEL = "quick-chat.connected-from";
15
-
16
- const WORKSPACE_TITLE = "Quick chats";
17
- const MAX_PAGES = 20;
18
-
19
- const PROVIDER_NAMES: Record<string, string> = { claude: "Claude", codex: "Codex", opencode: "OpenCode" };
20
-
21
- const SYSTEM_PROMPT = [
22
- "You are in a general chat that isn't attached to any project.",
23
- "Your working directory is a scratch folder the user doesn't look at, so don't assume there is code to read.",
24
- "Answer questions directly. If the user wants work done on a codebase, tell them they can connect this chat to a project.",
25
- ].join(" ");
26
-
27
- export class UserError extends Error {}
28
-
29
- export function defaultScratchDir(): string {
30
- return path.join(homedir(), ".paseo", "quick-chat");
31
- }
32
-
33
- function norm(value: string): string {
34
- const resolved = path.resolve(value).replace(/[\\/]+$/, "");
35
- return process.platform === "win32" ? resolved.toLowerCase() : resolved;
36
- }
37
-
38
- function samePath(a: string | null | undefined, b: string): boolean {
39
- return Boolean(a) && norm(a!) === norm(b);
40
- }
41
-
42
- function isUnder(child: string | null | undefined, root: string): boolean {
43
- if (!child) return false;
44
- const a = norm(child);
45
- const b = norm(root);
46
- return a === b || a.startsWith(b + path.sep);
47
- }
48
-
49
- function workspaceDir(workspace: Workspace): string {
50
- return workspace.workspaceDirectory ?? workspace.projectRootPath;
51
- }
52
-
53
- function providerLabel(id: string): string {
54
- return PROVIDER_NAMES[id] ?? id.charAt(0).toUpperCase() + id.slice(1);
55
- }
56
-
57
- function isBusy(agent: Agent): boolean {
58
- return agent.status === "running" || agent.status === "initializing" || Boolean(agent.activeTurn);
59
- }
60
-
61
- export class Chats {
62
- /** Serialises workspace setup, so two chats started at once don't register the folder twice. */
63
- private workspace: Promise<string> | null = null;
64
- /** Connects in flight, keyed by chat, so a double click doesn't start two copies. */
65
- private connecting = new Map<string, Promise<{ agentId: string; workspaceId: string }>>();
66
-
67
- constructor(
68
- private readonly scratchDir = defaultScratchDir(),
69
- /** Where to report what happened; shown under the plugin's Logs in Paseo. */
70
- private readonly log: (message: string) => void = (message) => console.log(`[Quick Chat] ${message}`),
71
- ) {}
72
-
73
- /** Quick chats are the agents in the chats folder, however they were started. */
74
- isChat(cwd: string | null | undefined): boolean {
75
- return isUnder(cwd, this.scratchDir);
76
- }
77
-
78
- /** The Quick chats workspace, set up first if needed. Opened in Paseo, it's a native blank chat. */
79
- openWorkspace(paseo: PaseoApi): Promise<string> {
80
- return this.ensureWorkspace(paseo);
81
- }
82
-
83
- get directory(): string {
84
- return this.scratchDir;
85
- }
86
-
87
- /** Adds the "no project" note to an agent started in the chats folder. */
88
- withSystemPrompt<Config extends { cwd: string; systemPrompt?: string }>(config: Config): Config | null {
89
- if (!this.isChat(config.cwd) || config.systemPrompt?.includes(SYSTEM_PROMPT)) return null;
90
- this.log(`Added the no-project note to a new chat in ${config.cwd}`);
91
- return { ...config, systemPrompt: config.systemPrompt?.trim() ? `${config.systemPrompt.trim()}
92
-
93
- ${SYSTEM_PROMPT}` : SYSTEM_PROMPT };
94
- }
95
-
96
- async projects(paseo: PaseoApi): Promise<ProjectChoice[]> {
97
- return (await listWorkspaces(paseo))
98
- .filter((workspace) => !workspace.archivingAt && !workspace.internal && !samePath(workspaceDir(workspace), this.scratchDir))
99
- .map((workspace) => ({
100
- workspaceId: workspace.id,
101
- label: projectLabel(workspace),
102
- directory: workspaceDir(workspace),
103
- shortDirectory: shortPath(workspaceDir(workspace)),
104
- worktree: workspace.workspaceKind === "worktree",
105
- }))
106
- .sort((a, b) => a.label.localeCompare(b.label));
107
- }
108
-
109
- connect(
110
- paseo: PaseoApi,
111
- input: { agentId: string; workspaceId: string; archiveOriginal: boolean },
112
- ): Promise<{ agentId: string; workspaceId: string }> {
113
- const running = this.connecting.get(input.agentId);
114
- if (running) return running;
115
- this.log(`Connecting chat ${input.agentId.slice(0, 8)} to workspace ${input.workspaceId}`);
116
- const task = this.connectNow(paseo, input)
117
- .then(
118
- (result) => {
119
- this.log(`Connected chat ${input.agentId.slice(0, 8)}: continues as ${result.agentId.slice(0, 8)}${input.archiveOriginal ? "; chat archived" : ""}`);
120
- return result;
121
- },
122
- (error: unknown) => {
123
- this.log(`Couldn't connect chat ${input.agentId.slice(0, 8)}: ${error instanceof Error ? error.message : String(error)}`);
124
- throw error;
125
- },
126
- )
127
- .finally(() => this.connecting.delete(input.agentId));
128
- this.connecting.set(input.agentId, task);
129
- return task;
130
- }
131
-
132
- private async connectNow(
133
- paseo: PaseoApi,
134
- input: { agentId: string; workspaceId: string; archiveOriginal: boolean },
135
- ): Promise<{ agentId: string; workspaceId: string }> {
136
- const chat = (await paseo.agents.ref(input.agentId).refresh())?.agent;
137
- if (!chat) throw new UserError("That chat no longer exists.");
138
- if (!this.isChat(chat.cwd)) throw new UserError("Only quick chats can be connected to a project.");
139
- if (isBusy(chat)) throw new UserError("Still replying. Try again when it's done.");
140
- if (chat.pendingPermissions.length > 0) {
141
- throw new UserError("Waiting for you to allow or deny something. Answer it first.");
142
- }
143
-
144
- const workspace = (await listWorkspaces(paseo)).find((entry) => entry.id === input.workspaceId);
145
- if (!workspace || workspace.archivingAt) throw new UserError("That project isn't open any more.");
146
- const directory = workspaceDir(workspace);
147
- if (samePath(directory, this.scratchDir)) throw new UserError("Pick a real project.");
148
-
149
- // A retry after a timeout or a daemon restart finds the copy it already started.
150
- const existing = (await listAgents(paseo, { [CONNECTED_FROM_LABEL]: chat.id })).find(
151
- (agent) => agent.workspaceId === workspace.id,
152
- );
153
- if (existing) {
154
- await this.finish(paseo, chat, existing.id, input.archiveOriginal);
155
- return { agentId: existing.id, workspaceId: workspace.id };
156
- }
157
-
158
- const page = await paseo.agents.ref(chat.id).timeline.refetch({ direction: "tail", limit: 500 });
159
- const transcript = buildTranscript(page.entries.map((entry) => entry.item));
160
- const model = chat.model ?? chat.runtimeInfo?.model ?? (await defaultModel(paseo, chat.provider));
161
- if (!model) throw new UserError(`No ${providerLabel(chat.provider)} model found.`);
162
-
163
- // The chat's mode is left behind on purpose: a project gets the provider's default (and so its
164
- // usual permission prompts), not whatever was fine in a scratch folder.
165
- const copy = await paseo.workspaces.ref(workspace.id).agents.create({
166
- config: {
167
- provider: `${chat.provider}/${model}`,
168
- ...(chat.thinkingOptionId ? { thinkingOptionId: chat.thinkingOptionId } : {}),
169
- },
170
- title: chat.title?.trim() || "Chat",
171
- prompt: connectPrompt(transcript, directory),
172
- idempotencyKey: `quick-chat.connect.${chat.id}.${workspace.id}`,
173
- labels: { [CONNECTED_FROM_LABEL]: chat.id },
174
- });
175
- await this.finish(paseo, chat, copy.id, input.archiveOriginal);
176
- return { agentId: copy.id, workspaceId: workspace.id };
177
- }
178
-
179
- /** Best effort: the copy exists by now, and that's what the user asked for. */
180
- private async finish(paseo: PaseoApi, chat: Agent, copyId: string, archive: boolean): Promise<void> {
181
- if (!archive || chat.archivedAt) return;
182
- try {
183
- await paseo.agents.ref(chat.id).archive();
184
- } catch (error) {
185
- console.error(`[Quick Chat] connected ${chat.id} to ${copyId} but couldn't archive the chat`, error);
186
- }
187
- }
188
-
189
- private ensureWorkspace(paseo: PaseoApi): Promise<string> {
190
- const pending = (this.workspace ??= this.findOrCreateWorkspace(paseo));
191
- // A failure (or a workspace archived since) shouldn't stick: the next chat tries again.
192
- return pending.then(
193
- async (id) => {
194
- const current = await paseo.workspaces.ref(id).refresh().catch(() => null);
195
- if (current && !current.archivingAt) return id;
196
- if (this.workspace === pending) this.workspace = null;
197
- return this.ensureWorkspace(paseo);
198
- },
199
- (error: unknown) => {
200
- if (this.workspace === pending) this.workspace = null;
201
- throw error;
202
- },
203
- );
204
- }
205
-
206
- private async findOrCreateWorkspace(paseo: PaseoApi): Promise<string> {
207
- // Recreated every time: someone may have deleted the folder since the last chat.
208
- await mkdir(this.scratchDir, { recursive: true });
209
- // A background workspace: opened by the plugin, but not listed as a project in the sidebar.
210
- const found = (await listWorkspaces(paseo, true)).find(
211
- (workspace) => workspace.background && !workspace.archivingAt && samePath(workspaceDir(workspace), this.scratchDir),
212
- );
213
- if (found) {
214
- if (found.title !== WORKSPACE_TITLE) await paseo.workspaces.ref(found.id).setTitle(WORKSPACE_TITLE).catch(() => undefined);
215
- this.log(`Using the Quick chats workspace ${found.id} (${this.scratchDir})`);
216
- return found.id;
217
- }
218
- const created = await paseo.workspaces.create({
219
- source: { kind: "directory", path: this.scratchDir },
220
- title: WORKSPACE_TITLE,
221
- background: true,
222
- });
223
- this.log(`Created the Quick chats workspace ${created.id} (${this.scratchDir})`);
224
- return created.id;
225
- }
226
- }
227
-
228
- function projectLabel(workspace: Workspace): string {
229
- const project = workspace.projectCustomName?.trim() || workspace.projectDisplayName;
230
- if (workspace.workspaceKind === "directory" || workspace.workspaceKind === "checkout") return project;
231
- const name = workspace.title?.trim() || workspace.name;
232
- return name && name !== project ? `${project} · ${name}` : project;
233
- }
234
-
235
- async function defaultModel(paseo: PaseoApi, provider: string): Promise<string | null> {
236
- try {
237
- const { models } = await paseo.providers.listModels(provider);
238
- return (models?.find((entry) => entry.isDefault) ?? models?.[0])?.id ?? null;
239
- } catch {
240
- return null;
241
- }
242
- }
243
-
244
- async function listAgents(paseo: PaseoApi, labels: Record<string, string>): Promise<Agent[]> {
245
- const agents: Agent[] = [];
246
- let cursor: string | undefined;
247
- for (let page = 0; page < MAX_PAGES; page += 1) {
248
- const result = await paseo.agents.list({
249
- ...(Object.keys(labels).length ? { filter: { labels } } : {}),
250
- page: { limit: 200, ...(cursor ? { cursor } : {}) },
251
- });
252
- for (const { agent } of result.entries) agents.push(agent);
253
- if (!result.pageInfo.hasMore || !result.pageInfo.nextCursor) break;
254
- cursor = result.pageInfo.nextCursor;
255
- }
256
- return agents;
257
- }
258
-
259
- async function listWorkspaces(paseo: PaseoApi, includeBackground = false): Promise<Workspace[]> {
260
- const workspaces: Workspace[] = [];
261
- let cursor: string | undefined;
262
- for (let page = 0; page < MAX_PAGES; page += 1) {
263
- const result = await paseo.workspaces.list({
264
- ...(includeBackground ? { filter: { includeBackground: true } } : {}),
265
- page: { limit: 200, ...(cursor ? { cursor } : {}) },
266
- });
267
- workspaces.push(...result.entries);
268
- if (!result.pageInfo.hasMore || !result.pageInfo.nextCursor) break;
269
- cursor = result.pageInfo.nextCursor;
270
- }
271
- return workspaces;
272
- }
1
+ import { mkdir } from "node:fs/promises";
2
+ import { homedir } from "node:os";
3
+ import path from "node:path";
4
+ import type { PluginHandlerContext } from "@getpaseo/plugin/server";
5
+ import type { ProjectChoice } from "../shared/rpc";
6
+ import { buildTranscript, connectPrompt } from "./handoff";
7
+ import { shortPath } from "./folders";
8
+
9
+ export type PaseoApi = PluginHandlerContext["paseo"];
10
+ type Agent = Awaited<ReturnType<PaseoApi["agents"]["list"]>>["entries"][number]["agent"];
11
+ type Workspace = Awaited<ReturnType<PaseoApi["workspaces"]["list"]>>["entries"][number];
12
+
13
+ /** On the agent a chat was carried over into: the chat it came from. */
14
+ export const CONNECTED_FROM_LABEL = "quick-chat.connected-from";
15
+
16
+ const WORKSPACE_TITLE = "Quick chats";
17
+ const MAX_PAGES = 20;
18
+
19
+ const PROVIDER_NAMES: Record<string, string> = { claude: "Claude", codex: "Codex", opencode: "OpenCode" };
20
+
21
+ const SYSTEM_PROMPT = [
22
+ "You are in a general chat that isn't attached to any project.",
23
+ "Your working directory is a scratch folder the user doesn't look at, so don't assume there is code to read.",
24
+ "Answer questions directly. If the user wants work done on a codebase, tell them they can connect this chat to a project.",
25
+ ].join(" ");
26
+
27
+ export class UserError extends Error {}
28
+
29
+ export function defaultScratchDir(): string {
30
+ return path.join(homedir(), ".paseo", "quick-chat");
31
+ }
32
+
33
+ function norm(value: string): string {
34
+ const resolved = path.resolve(value).replace(/[\\/]+$/, "");
35
+ return process.platform === "win32" ? resolved.toLowerCase() : resolved;
36
+ }
37
+
38
+ function samePath(a: string | null | undefined, b: string): boolean {
39
+ return Boolean(a) && norm(a!) === norm(b);
40
+ }
41
+
42
+ function isUnder(child: string | null | undefined, root: string): boolean {
43
+ if (!child) return false;
44
+ const a = norm(child);
45
+ const b = norm(root);
46
+ return a === b || a.startsWith(b + path.sep);
47
+ }
48
+
49
+ function workspaceDir(workspace: Workspace): string {
50
+ return workspace.workspaceDirectory ?? workspace.projectRootPath;
51
+ }
52
+
53
+ function providerLabel(id: string): string {
54
+ return PROVIDER_NAMES[id] ?? id.charAt(0).toUpperCase() + id.slice(1);
55
+ }
56
+
57
+ function isBusy(agent: Agent): boolean {
58
+ return agent.status === "running" || agent.status === "initializing" || Boolean(agent.activeTurn);
59
+ }
60
+
61
+ export class Chats {
62
+ /** Serialises workspace setup, so two chats started at once don't register the folder twice. */
63
+ private workspace: Promise<string> | null = null;
64
+ /** Connects in flight, keyed by chat, so a double click doesn't start two copies. */
65
+ private connecting = new Map<string, Promise<{ agentId: string; workspaceId: string }>>();
66
+
67
+ constructor(
68
+ private readonly scratchDir = defaultScratchDir(),
69
+ /** Where to report what happened; shown under the plugin's Logs in Paseo. */
70
+ private readonly log: (message: string) => void = (message) => console.log(`[Quick Chat] ${message}`),
71
+ ) {}
72
+
73
+ /** Quick chats are the agents in the chats folder, however they were started. */
74
+ isChat(cwd: string | null | undefined): boolean {
75
+ return isUnder(cwd, this.scratchDir);
76
+ }
77
+
78
+ /** The Quick chats workspace, set up first if needed. Opened in Paseo, it's a native blank chat. */
79
+ openWorkspace(paseo: PaseoApi): Promise<string> {
80
+ return this.ensureWorkspace(paseo);
81
+ }
82
+
83
+ get directory(): string {
84
+ return this.scratchDir;
85
+ }
86
+
87
+ /** Adds the "no project" note to an agent started in the chats folder. */
88
+ withSystemPrompt<Config extends { cwd: string; systemPrompt?: string }>(config: Config): Config | null {
89
+ if (!this.isChat(config.cwd) || config.systemPrompt?.includes(SYSTEM_PROMPT)) return null;
90
+ this.log(`Added the no-project note to a new chat in ${config.cwd}`);
91
+ return { ...config, systemPrompt: config.systemPrompt?.trim() ? `${config.systemPrompt.trim()}
92
+
93
+ ${SYSTEM_PROMPT}` : SYSTEM_PROMPT };
94
+ }
95
+
96
+ async projects(paseo: PaseoApi): Promise<ProjectChoice[]> {
97
+ return (await listWorkspaces(paseo))
98
+ .filter((workspace) => !workspace.archivingAt && !workspace.internal && !samePath(workspaceDir(workspace), this.scratchDir))
99
+ .map((workspace) => ({
100
+ workspaceId: workspace.id,
101
+ label: projectLabel(workspace),
102
+ directory: workspaceDir(workspace),
103
+ shortDirectory: shortPath(workspaceDir(workspace)),
104
+ worktree: workspace.workspaceKind === "worktree",
105
+ }))
106
+ .sort((a, b) => a.label.localeCompare(b.label));
107
+ }
108
+
109
+ connect(
110
+ paseo: PaseoApi,
111
+ input: { agentId: string; workspaceId: string; archiveOriginal: boolean },
112
+ ): Promise<{ agentId: string; workspaceId: string }> {
113
+ const running = this.connecting.get(input.agentId);
114
+ if (running) return running;
115
+ this.log(`Connecting chat ${input.agentId.slice(0, 8)} to workspace ${input.workspaceId}`);
116
+ const task = this.connectNow(paseo, input)
117
+ .then(
118
+ (result) => {
119
+ this.log(`Connected chat ${input.agentId.slice(0, 8)}: continues as ${result.agentId.slice(0, 8)}${input.archiveOriginal ? "; chat archived" : ""}`);
120
+ return result;
121
+ },
122
+ (error: unknown) => {
123
+ this.log(`Couldn't connect chat ${input.agentId.slice(0, 8)}: ${error instanceof Error ? error.message : String(error)}`);
124
+ throw error;
125
+ },
126
+ )
127
+ .finally(() => this.connecting.delete(input.agentId));
128
+ this.connecting.set(input.agentId, task);
129
+ return task;
130
+ }
131
+
132
+ private async connectNow(
133
+ paseo: PaseoApi,
134
+ input: { agentId: string; workspaceId: string; archiveOriginal: boolean },
135
+ ): Promise<{ agentId: string; workspaceId: string }> {
136
+ const chat = (await paseo.agents.ref(input.agentId).refresh())?.agent;
137
+ if (!chat) throw new UserError("That chat no longer exists.");
138
+ if (!this.isChat(chat.cwd)) throw new UserError("Only quick chats can be connected to a project.");
139
+ if (isBusy(chat)) throw new UserError("Still replying. Try again when it's done.");
140
+ if (chat.pendingPermissions.length > 0) {
141
+ throw new UserError("Waiting for you to allow or deny something. Answer it first.");
142
+ }
143
+
144
+ const workspace = (await listWorkspaces(paseo)).find((entry) => entry.id === input.workspaceId);
145
+ if (!workspace || workspace.archivingAt) throw new UserError("That project isn't open any more.");
146
+ const directory = workspaceDir(workspace);
147
+ if (samePath(directory, this.scratchDir)) throw new UserError("Pick a real project.");
148
+
149
+ // A retry after a timeout or a daemon restart finds the copy it already started.
150
+ const existing = (await listAgents(paseo, { [CONNECTED_FROM_LABEL]: chat.id })).find(
151
+ (agent) => agent.workspaceId === workspace.id,
152
+ );
153
+ if (existing) {
154
+ await this.finish(paseo, chat, existing.id, input.archiveOriginal);
155
+ return { agentId: existing.id, workspaceId: workspace.id };
156
+ }
157
+
158
+ const page = await paseo.agents.ref(chat.id).timeline.refetch({ direction: "tail", limit: 500 });
159
+ const transcript = buildTranscript(page.entries.map((entry) => entry.item));
160
+ const model = chat.model ?? chat.runtimeInfo?.model ?? (await defaultModel(paseo, chat.provider));
161
+ if (!model) throw new UserError(`No ${providerLabel(chat.provider)} model found.`);
162
+
163
+ // The chat's mode is left behind on purpose: a project gets the provider's default (and so its
164
+ // usual permission prompts), not whatever was fine in a scratch folder.
165
+ const copy = await paseo.workspaces.ref(workspace.id).agents.create({
166
+ config: {
167
+ provider: `${chat.provider}/${model}`,
168
+ ...(chat.thinkingOptionId ? { thinkingOptionId: chat.thinkingOptionId } : {}),
169
+ },
170
+ title: chat.title?.trim() || "Chat",
171
+ prompt: connectPrompt(transcript, directory),
172
+ idempotencyKey: `quick-chat.connect.${chat.id}.${workspace.id}`,
173
+ labels: { [CONNECTED_FROM_LABEL]: chat.id },
174
+ });
175
+ await this.finish(paseo, chat, copy.id, input.archiveOriginal);
176
+ return { agentId: copy.id, workspaceId: workspace.id };
177
+ }
178
+
179
+ /** Best effort: the copy exists by now, and that's what the user asked for. */
180
+ private async finish(paseo: PaseoApi, chat: Agent, copyId: string, archive: boolean): Promise<void> {
181
+ if (!archive || chat.archivedAt) return;
182
+ try {
183
+ await paseo.agents.ref(chat.id).archive();
184
+ } catch (error) {
185
+ console.error(`[Quick Chat] connected ${chat.id} to ${copyId} but couldn't archive the chat`, error);
186
+ }
187
+ }
188
+
189
+ private ensureWorkspace(paseo: PaseoApi): Promise<string> {
190
+ const pending = (this.workspace ??= this.findOrCreateWorkspace(paseo));
191
+ // A failure (or a workspace archived since) shouldn't stick: the next chat tries again.
192
+ return pending.then(
193
+ async (id) => {
194
+ const current = await paseo.workspaces.ref(id).refresh().catch(() => null);
195
+ if (current && !current.archivingAt) return id;
196
+ if (this.workspace === pending) this.workspace = null;
197
+ return this.ensureWorkspace(paseo);
198
+ },
199
+ (error: unknown) => {
200
+ if (this.workspace === pending) this.workspace = null;
201
+ throw error;
202
+ },
203
+ );
204
+ }
205
+
206
+ private async findOrCreateWorkspace(paseo: PaseoApi): Promise<string> {
207
+ // Recreated every time: someone may have deleted the folder since the last chat.
208
+ await mkdir(this.scratchDir, { recursive: true });
209
+ // A background workspace: opened by the plugin, but not listed as a project in the sidebar.
210
+ const found = (await listWorkspaces(paseo, true)).find(
211
+ (workspace) => workspace.background && !workspace.archivingAt && samePath(workspaceDir(workspace), this.scratchDir),
212
+ );
213
+ if (found) {
214
+ if (found.title !== WORKSPACE_TITLE) await paseo.workspaces.ref(found.id).setTitle(WORKSPACE_TITLE).catch(() => undefined);
215
+ this.log(`Using the Quick chats workspace ${found.id} (${this.scratchDir})`);
216
+ return found.id;
217
+ }
218
+ const created = await paseo.workspaces.create({
219
+ source: { kind: "directory", path: this.scratchDir },
220
+ title: WORKSPACE_TITLE,
221
+ background: true,
222
+ });
223
+ this.log(`Created the Quick chats workspace ${created.id} (${this.scratchDir})`);
224
+ return created.id;
225
+ }
226
+ }
227
+
228
+ function projectLabel(workspace: Workspace): string {
229
+ const project = workspace.projectCustomName?.trim() || workspace.projectDisplayName;
230
+ if (workspace.workspaceKind === "directory" || workspace.workspaceKind === "checkout") return project;
231
+ const name = workspace.title?.trim() || workspace.name;
232
+ return name && name !== project ? `${project} · ${name}` : project;
233
+ }
234
+
235
+ async function defaultModel(paseo: PaseoApi, provider: string): Promise<string | null> {
236
+ try {
237
+ const { models } = await paseo.providers.listModels(provider);
238
+ return (models?.find((entry) => entry.isDefault) ?? models?.[0])?.id ?? null;
239
+ } catch {
240
+ return null;
241
+ }
242
+ }
243
+
244
+ async function listAgents(paseo: PaseoApi, labels: Record<string, string>): Promise<Agent[]> {
245
+ const agents: Agent[] = [];
246
+ let cursor: string | undefined;
247
+ for (let page = 0; page < MAX_PAGES; page += 1) {
248
+ const result = await paseo.agents.list({
249
+ ...(Object.keys(labels).length ? { filter: { labels } } : {}),
250
+ page: { limit: 200, ...(cursor ? { cursor } : {}) },
251
+ });
252
+ for (const { agent } of result.entries) agents.push(agent);
253
+ if (!result.pageInfo.hasMore || !result.pageInfo.nextCursor) break;
254
+ cursor = result.pageInfo.nextCursor;
255
+ }
256
+ return agents;
257
+ }
258
+
259
+ async function listWorkspaces(paseo: PaseoApi, includeBackground = false): Promise<Workspace[]> {
260
+ const workspaces: Workspace[] = [];
261
+ let cursor: string | undefined;
262
+ for (let page = 0; page < MAX_PAGES; page += 1) {
263
+ const result = await paseo.workspaces.list({
264
+ ...(includeBackground ? { filter: { includeBackground: true } } : {}),
265
+ page: { limit: 200, ...(cursor ? { cursor } : {}) },
266
+ });
267
+ workspaces.push(...result.entries);
268
+ if (!result.pageInfo.hasMore || !result.pageInfo.nextCursor) break;
269
+ cursor = result.pageInfo.nextCursor;
270
+ }
271
+ return workspaces;
272
+ }
package/shared/rpc.ts CHANGED
@@ -1,51 +1,51 @@
1
- import { defineRpc } from "@getpaseo/plugin";
2
- import { z } from "zod";
3
-
4
- export const ProjectChoiceSchema = z.object({
5
- workspaceId: z.string(),
6
- /** Project name, then the workspace (branch or worktree) when it isn't the main checkout. */
7
- label: z.string(),
8
- directory: z.string(),
9
- /** The directory as shown: `~/…` under the home folder. */
10
- shortDirectory: z.string(),
11
- worktree: z.boolean(),
12
- });
13
- export type ProjectChoice = z.output<typeof ProjectChoiceSchema>;
14
-
15
- /** Sets up the Quick chats workspace if needed. Chats are the agents in it. */
16
- export const openChats = defineRpc({
17
- name: "quick-chat.open",
18
- input: z.object({}),
19
- /** The folder chats run in: agents anywhere inside it are quick chats. */
20
- output: z.object({ workspaceId: z.string(), directory: z.string() }),
21
- });
22
-
23
- export const listProjects = defineRpc({
24
- name: "quick-chat.projects",
25
- input: z.object({}),
26
- output: z.object({ projects: z.array(ProjectChoiceSchema) }),
27
- });
28
-
29
- /** Folders on the daemon host matching a search, as Paseo's own "Add project" finds them. */
30
- export const findFolders = defineRpc({
31
- name: "quick-chat.folders",
32
- input: z.object({ query: z.string() }),
33
- output: z.object({
34
- folders: z.array(z.object({ directory: z.string(), shortDirectory: z.string() })),
35
- /** Set when the search isn't available (a daemon that needs a password, for one). */
36
- error: z.string().nullable(),
37
- }),
38
- });
39
-
40
- export const connectChat = defineRpc({
41
- name: "quick-chat.connect",
42
- input: z.object({
43
- agentId: z.string(),
44
- /** An open project's workspace, or `directory` to open a folder as a project first. */
45
- workspaceId: z.string().optional(),
46
- directory: z.string().optional(),
47
- /** Archive the chat once its copy has started in the project. Omitted: the preference decides. */
48
- archiveOriginal: z.boolean().optional(),
49
- }),
50
- output: z.object({ agentId: z.string(), workspaceId: z.string() }),
51
- });
1
+ import { defineRpc } from "@getpaseo/plugin";
2
+ import { z } from "zod";
3
+
4
+ export const ProjectChoiceSchema = z.object({
5
+ workspaceId: z.string(),
6
+ /** Project name, then the workspace (branch or worktree) when it isn't the main checkout. */
7
+ label: z.string(),
8
+ directory: z.string(),
9
+ /** The directory as shown: `~/…` under the home folder. */
10
+ shortDirectory: z.string(),
11
+ worktree: z.boolean(),
12
+ });
13
+ export type ProjectChoice = z.output<typeof ProjectChoiceSchema>;
14
+
15
+ /** Sets up the Quick chats workspace if needed. Chats are the agents in it. */
16
+ export const openChats = defineRpc({
17
+ name: "quick-chat.open",
18
+ input: z.object({}),
19
+ /** The folder chats run in: agents anywhere inside it are quick chats. */
20
+ output: z.object({ workspaceId: z.string(), directory: z.string() }),
21
+ });
22
+
23
+ export const listProjects = defineRpc({
24
+ name: "quick-chat.projects",
25
+ input: z.object({}),
26
+ output: z.object({ projects: z.array(ProjectChoiceSchema) }),
27
+ });
28
+
29
+ /** Folders on the daemon host matching a search, as Paseo's own "Add project" finds them. */
30
+ export const findFolders = defineRpc({
31
+ name: "quick-chat.folders",
32
+ input: z.object({ query: z.string() }),
33
+ output: z.object({
34
+ folders: z.array(z.object({ directory: z.string(), shortDirectory: z.string() })),
35
+ /** Set when the search isn't available (a daemon that needs a password, for one). */
36
+ error: z.string().nullable(),
37
+ }),
38
+ });
39
+
40
+ export const connectChat = defineRpc({
41
+ name: "quick-chat.connect",
42
+ input: z.object({
43
+ agentId: z.string(),
44
+ /** An open project's workspace, or `directory` to open a folder as a project first. */
45
+ workspaceId: z.string().optional(),
46
+ directory: z.string().optional(),
47
+ /** Archive the chat once its copy has started in the project. Omitted: the preference decides. */
48
+ archiveOriginal: z.boolean().optional(),
49
+ }),
50
+ output: z.object({ agentId: z.string(), workspaceId: z.string() }),
51
+ });