@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 +21 -0
- package/OVERVIEW.md +28 -0
- package/README.md +92 -2
- package/client/chats-workspace.ts +32 -0
- package/client/open-chats.tsx +47 -0
- package/client/pills.tsx +130 -0
- package/client/project-picker.tsx +301 -0
- package/client/screens.tsx +55 -0
- package/client/settings-screen.tsx +46 -0
- package/client/ui.tsx +50 -0
- package/images/1-chat.png +0 -0
- package/images/2-connect.png +0 -0
- package/index.client.tsx +59 -0
- package/index.server.ts +52 -0
- package/package.json +55 -4
- package/paseo-plugin.json +12 -0
- package/server/chats.ts +272 -0
- package/server/folders.ts +149 -0
- package/server/handoff.ts +82 -0
- package/shared/preferences.ts +16 -0
- package/shared/rpc.ts +51 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { access, readdir } from "node:fs/promises";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Folder search for the project picker. Paseo's own directory search reads the disk on every query
|
|
7
|
+
* (seconds per search on a large disk) and only looks under home, so a project on
|
|
8
|
+
* D:\ never shows. Instead, folders are listed once in the background and searched in memory, and
|
|
9
|
+
* the list is refreshed every few minutes.
|
|
10
|
+
*
|
|
11
|
+
* The walk stops at git repositories (a project's own folders are no project) and skips app data,
|
|
12
|
+
* build output and system folders.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const MAX_DEPTH = 6;
|
|
16
|
+
const MAX_FOLDERS = 200_000;
|
|
17
|
+
const REFRESH_MS = 10 * 60_000;
|
|
18
|
+
|
|
19
|
+
// App data, build output and system folders; Windows' legacy junctions repeat AppData twice.
|
|
20
|
+
const NOISE = new Set([
|
|
21
|
+
"appdata",
|
|
22
|
+
"application data",
|
|
23
|
+
"local settings",
|
|
24
|
+
"node_modules",
|
|
25
|
+
"saved games",
|
|
26
|
+
"$recycle.bin",
|
|
27
|
+
"system volume information",
|
|
28
|
+
"windows",
|
|
29
|
+
"program files",
|
|
30
|
+
"program files (x86)",
|
|
31
|
+
"programdata",
|
|
32
|
+
"msocache",
|
|
33
|
+
"recovery",
|
|
34
|
+
]);
|
|
35
|
+
|
|
36
|
+
export function isNoise(name: string): boolean {
|
|
37
|
+
return name.startsWith(".") || name.startsWith("$") || NOISE.has(name.toLowerCase());
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Shows paths under the home folder as `~/…`, as Paseo does. */
|
|
41
|
+
export function shortPath(path: string, home = homedir()): string {
|
|
42
|
+
const sep = path.includes("\\") ? "\\" : "/";
|
|
43
|
+
if (path.toLowerCase() === home.toLowerCase()) return "~";
|
|
44
|
+
return path.toLowerCase().startsWith((home + sep).toLowerCase()) ? `~${sep}${path.slice(home.length + 1)}` : path;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Where to look: the home folder, then other drives (Windows) or mounted volumes. */
|
|
48
|
+
export async function searchRoots(platform = process.platform, home = homedir()): Promise<string[]> {
|
|
49
|
+
if (platform === "win32") {
|
|
50
|
+
const homeDrive = home.slice(0, 1).toUpperCase();
|
|
51
|
+
const letters = "CDEFGHIJKLMNOPQRSTUVWXYZ".split("").filter((letter) => letter !== homeDrive);
|
|
52
|
+
const found = await Promise.all(letters.map((letter) => access(`${letter}:\\`).then(() => `${letter}:\\`, () => null)));
|
|
53
|
+
return [home, ...found.filter((root): root is string => root !== null)];
|
|
54
|
+
}
|
|
55
|
+
const mounts = platform === "darwin" ? "/Volumes" : "/mnt";
|
|
56
|
+
try {
|
|
57
|
+
const volumes = (await readdir(mounts, { withFileTypes: true })).filter((entry) => entry.isDirectory());
|
|
58
|
+
return [home, ...volumes.map((entry) => join(mounts, entry.name))];
|
|
59
|
+
} catch {
|
|
60
|
+
return [home];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Every folder under `roots`, breadth first, down to MAX_DEPTH, not inside git repositories. */
|
|
65
|
+
export async function listFolders(roots: string[], maxDepth = MAX_DEPTH, max = MAX_FOLDERS): Promise<string[]> {
|
|
66
|
+
const found: string[] = [];
|
|
67
|
+
const seen = new Set<string>();
|
|
68
|
+
let level = roots.map((root) => root);
|
|
69
|
+
for (let depth = 0; depth < maxDepth && level.length && found.length < max; depth += 1) {
|
|
70
|
+
const next: string[] = [];
|
|
71
|
+
await Promise.all(
|
|
72
|
+
level.map(async (dir) => {
|
|
73
|
+
let entries;
|
|
74
|
+
try {
|
|
75
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
76
|
+
} catch {
|
|
77
|
+
return; // No access, or gone.
|
|
78
|
+
}
|
|
79
|
+
// A repository is a project: list it, but not its own folders.
|
|
80
|
+
if (depth > 0 && entries.some((entry) => entry.name === ".git")) return;
|
|
81
|
+
for (const entry of entries) {
|
|
82
|
+
if (!entry.isDirectory() || isNoise(entry.name)) continue;
|
|
83
|
+
const path = join(dir, entry.name);
|
|
84
|
+
const key = path.toLowerCase();
|
|
85
|
+
if (seen.has(key)) continue;
|
|
86
|
+
seen.add(key);
|
|
87
|
+
found.push(path);
|
|
88
|
+
next.push(path);
|
|
89
|
+
}
|
|
90
|
+
}),
|
|
91
|
+
);
|
|
92
|
+
level = next;
|
|
93
|
+
}
|
|
94
|
+
return found.slice(0, max);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Letters and digits only, so "photo-editor" finds "Photo Editor" and "PhotoEditor". */
|
|
98
|
+
const squash = (text: string) => text.toLowerCase().replace(/[^\p{L}\p{N}]+/gu, "");
|
|
99
|
+
const baseName = (path: string) => path.replace(/[\\/]+$/, "").split(/[\\/]/).pop() ?? path;
|
|
100
|
+
const depthOf = (path: string) => path.split(/[\\/]/).filter(Boolean).length;
|
|
101
|
+
// Build output repeats project names ("target\debug\build\notes-app-1a2b…"); it goes last.
|
|
102
|
+
const BUILD = /[\\/](target|cargo-target|build|dist|out|bin|obj|debug|release|\.?cache)([\\/]|$)/i;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Folders whose name contains the search come first: exact names, then names starting with it,
|
|
106
|
+
* then the rest, shallower before deeper. Then folders with the search elsewhere in their path.
|
|
107
|
+
*/
|
|
108
|
+
export function rank(directories: string[], query: string): string[] {
|
|
109
|
+
const needle = squash(query);
|
|
110
|
+
if (!needle) return [];
|
|
111
|
+
const scored: { path: string; score: number }[] = [];
|
|
112
|
+
for (const path of directories) {
|
|
113
|
+
const name = squash(baseName(path));
|
|
114
|
+
const score = name === needle ? 0 : name.startsWith(needle) ? 1 : name.includes(needle) ? 2 : squash(path).includes(needle) ? 3 : -1;
|
|
115
|
+
if (score >= 0) scored.push({ path, score: score + (BUILD.test(path) ? 4 : 0) });
|
|
116
|
+
}
|
|
117
|
+
return scored.sort((a, b) => a.score - b.score || depthOf(a.path) - depthOf(b.path) || a.path.length - b.path.length).map((entry) => entry.path);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function folderSearch(roots: () => Promise<string[]> = () => searchRoots()) {
|
|
121
|
+
let index: { at: number; folders: Promise<string[]> } | null = null;
|
|
122
|
+
|
|
123
|
+
const folders = (): Promise<string[]> => {
|
|
124
|
+
const stale = !index || Date.now() - index.at > REFRESH_MS;
|
|
125
|
+
if (stale) {
|
|
126
|
+
const previous = index?.folders;
|
|
127
|
+
const fresh = roots().then((list) => listFolders(list));
|
|
128
|
+
index = { at: Date.now(), folders: fresh };
|
|
129
|
+
fresh.catch(() => (index = null));
|
|
130
|
+
// While a refresh runs, the previous list answers.
|
|
131
|
+
if (previous) return previous.catch(() => fresh);
|
|
132
|
+
}
|
|
133
|
+
return index!.folders;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
/** Starts listing folders, so the first search doesn't wait for it. */
|
|
138
|
+
warm(): void {
|
|
139
|
+
void folders().catch(() => undefined);
|
|
140
|
+
},
|
|
141
|
+
async find(query: string, limit = 12): Promise<string[]> {
|
|
142
|
+
if (!squash(query)) return [];
|
|
143
|
+
return rank(await folders(), query).slice(0, limit);
|
|
144
|
+
},
|
|
145
|
+
close(): void {
|
|
146
|
+
index = null;
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { AgentTimelineItem } from "@getpaseo/protocol/agent-types";
|
|
2
|
+
|
|
3
|
+
export type { AgentTimelineItem };
|
|
4
|
+
|
|
5
|
+
type ToolCall = Extract<AgentTimelineItem, { type: "tool_call" }>;
|
|
6
|
+
|
|
7
|
+
/** Transcripts longer than this keep the chat's first message and its most recent part. */
|
|
8
|
+
const TRANSCRIPT_LIMIT = 40_000;
|
|
9
|
+
/** How much of that first message is kept. */
|
|
10
|
+
const FIRST_MESSAGE_LIMIT = 6_000;
|
|
11
|
+
|
|
12
|
+
const CHAT_START = "<earlier-chat>";
|
|
13
|
+
const CHAT_END = "</earlier-chat>";
|
|
14
|
+
const GAP = "\n\n";
|
|
15
|
+
|
|
16
|
+
/** Trimmed, and cut to `limit` characters with an ellipsis when longer. */
|
|
17
|
+
function shorten(text: string, limit: number): string {
|
|
18
|
+
const value = text.trim();
|
|
19
|
+
if (value.length <= limit) return value;
|
|
20
|
+
return value.slice(0, limit) + "…";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The chat is quoted between CHAT_START and CHAT_END; a message containing either is reworded. */
|
|
24
|
+
function escapeMarkers(text: string): string {
|
|
25
|
+
return text.split(CHAT_START).join("[earlier chat:").split(CHAT_END).join("]");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** One line per tool call, without its output. */
|
|
29
|
+
function toolLine(call: ToolCall): string {
|
|
30
|
+
const { detail } = call;
|
|
31
|
+
if (detail.type === "shell") return "[ran `" + shorten(detail.command, 200) + "`]";
|
|
32
|
+
if (detail.type === "read") return "[read " + detail.filePath + "]";
|
|
33
|
+
if (detail.type === "write" || detail.type === "edit") return "[wrote " + detail.filePath + " in the scratch folder]";
|
|
34
|
+
if (detail.type === "search") return "[searched: " + shorten(detail.query, 120) + "]";
|
|
35
|
+
return "[" + call.name + "]";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The transcript line for a timeline item, or null for what isn't carried over (reasoning, empty replies). */
|
|
39
|
+
function lineFor(item: AgentTimelineItem): string | null {
|
|
40
|
+
switch (item.type) {
|
|
41
|
+
case "user_message":
|
|
42
|
+
return "User: " + escapeMarkers(item.text).trim();
|
|
43
|
+
case "assistant_message":
|
|
44
|
+
return item.text.trim() ? "Assistant: " + escapeMarkers(item.text).trim() : null;
|
|
45
|
+
case "tool_call":
|
|
46
|
+
return toolLine(item);
|
|
47
|
+
default:
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The conversation as plain text, oldest first: messages and one line per tool call. When it's
|
|
54
|
+
* longer than `limit`, the newest part is kept, starting at a whole entry, after the chat's first
|
|
55
|
+
* message.
|
|
56
|
+
*/
|
|
57
|
+
export function buildTranscript(timeline: readonly AgentTimelineItem[], limit = TRANSCRIPT_LIMIT): string {
|
|
58
|
+
const entries = timeline.map(lineFor).filter((line): line is string => line !== null);
|
|
59
|
+
const full = entries.join(GAP);
|
|
60
|
+
if (full.length <= limit) return full;
|
|
61
|
+
|
|
62
|
+
const opening = timeline.find((item) => item.type === "user_message");
|
|
63
|
+
const lead = opening ? "User (first message): " + shorten(escapeMarkers(opening.text), FIRST_MESSAGE_LIMIT) + GAP : "";
|
|
64
|
+
let recent = full.slice(-limit);
|
|
65
|
+
const boundary = recent.indexOf(GAP);
|
|
66
|
+
if (boundary >= 0) recent = recent.slice(boundary + GAP.length);
|
|
67
|
+
return lead + "[… earlier messages omitted …]" + GAP + recent;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** The first message of the agent that continues a chat in a project. */
|
|
71
|
+
export function connectPrompt(transcript: string, projectDirectory: string): string {
|
|
72
|
+
const chat = transcript || "(The chat had no messages yet.)";
|
|
73
|
+
return `This conversation started as a general chat with no project. The user has now connected it to the project in
|
|
74
|
+
${projectDirectory}, which is your working directory. Here is the chat so far, oldest first:
|
|
75
|
+
|
|
76
|
+
${CHAT_START}
|
|
77
|
+
${chat}
|
|
78
|
+
${CHAT_END}
|
|
79
|
+
|
|
80
|
+
Files the chat mentions writing were in a separate scratch folder, not in this project.
|
|
81
|
+
Carry on from where the chat left off. Look at the project before changing anything, and reply briefly to confirm you have the context.`;
|
|
82
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineSettings } from "@getpaseo/plugin";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
export const preferences = defineSettings({
|
|
5
|
+
id: "preferences",
|
|
6
|
+
scope: "host",
|
|
7
|
+
version: 1,
|
|
8
|
+
schema: z.object({
|
|
9
|
+
/** Once a chat continues in a project, archive the chat so it isn't in two places. */
|
|
10
|
+
archiveAfterConnect: z.boolean().default(true),
|
|
11
|
+
/** Tell agents started in Quick chats that there's no project, so they don't go looking for code. */
|
|
12
|
+
noProjectNote: z.boolean().default(true),
|
|
13
|
+
}),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export type Preferences = z.output<typeof preferences.schema>;
|
package/shared/rpc.ts
ADDED
|
@@ -0,0 +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
|
+
});
|