@koinzhang/paseo-plugin-inbox 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/CHANGELOG.md +30 -0
- package/LICENSE +21 -0
- package/README.md +36 -0
- package/client/agent-status.tsx +129 -0
- package/client/header-button.ts +127 -0
- package/client/inbox-surface.tsx +1369 -0
- package/client/last-exchange.ts +49 -0
- package/client/panel-visibility.ts +45 -0
- package/client/selection.ts +50 -0
- package/client/use-inbox-filters.ts +83 -0
- package/client/web.ts +84 -0
- package/client/workspace-panel.tsx +18 -0
- package/index.client.tsx +74 -0
- package/index.server.ts +17 -0
- package/package.json +43 -0
- package/paseo-plugin.json +7 -0
- package/server/agents.ts +106 -0
- package/server/daemon.ts +85 -0
- package/server/directory.ts +63 -0
- package/server/handlers.ts +144 -0
- package/server/project-key.ts +42 -0
- package/server/store.ts +394 -0
- package/server/tags.ts +41 -0
- package/shared/agent-status.ts +39 -0
- package/shared/contracts.ts +192 -0
- package/shared/filter-settings.ts +74 -0
- package/shared/item-title.ts +8 -0
- package/shared/last-exchange.ts +124 -0
- package/shared/note.ts +4 -0
- package/shared/plugin-id.ts +4 -0
- package/shared/project-key.ts +55 -0
- package/shared/slash-command.ts +9 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { ExchangeCursor, ExchangePage, LastExchange } from "../shared/last-exchange.ts";
|
|
2
|
+
import { LAST_EXCHANGE_PAGE_LIMIT, readLastExchange } from "../shared/last-exchange.ts";
|
|
3
|
+
|
|
4
|
+
type TimelineApi = {
|
|
5
|
+
agents: {
|
|
6
|
+
ref: (agentId: string) => {
|
|
7
|
+
timeline: {
|
|
8
|
+
refetch: (options: {
|
|
9
|
+
projection?: "canonical" | "projected";
|
|
10
|
+
direction?: "tail" | "before";
|
|
11
|
+
cursor?: ExchangeCursor;
|
|
12
|
+
limit?: number;
|
|
13
|
+
}) => Promise<ExchangePage>;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
async function readProjection(
|
|
20
|
+
paseo: TimelineApi,
|
|
21
|
+
agentId: string,
|
|
22
|
+
projection: "projected" | "canonical",
|
|
23
|
+
): Promise<LastExchange> {
|
|
24
|
+
const timeline = paseo.agents.ref(agentId).timeline;
|
|
25
|
+
return readLastExchange(async ({ direction, cursor }) => {
|
|
26
|
+
const page = await timeline.refetch({
|
|
27
|
+
projection,
|
|
28
|
+
direction,
|
|
29
|
+
limit: LAST_EXCHANGE_PAGE_LIMIT,
|
|
30
|
+
...(cursor !== undefined ? { cursor } : {}),
|
|
31
|
+
});
|
|
32
|
+
if (page.error) throw new Error(page.error);
|
|
33
|
+
return page;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Latest user prompt and agent reply from the host timeline.
|
|
39
|
+
* Prefer the projected text the app shows, then the canonical timeline.
|
|
40
|
+
*/
|
|
41
|
+
export async function fetchLastExchange(paseo: TimelineApi, agentId: string): Promise<LastExchange> {
|
|
42
|
+
try {
|
|
43
|
+
const projected = await readProjection(paseo, agentId, "projected");
|
|
44
|
+
if (projected.prompt || projected.agent) return projected;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.warn("[inbox] projected timeline exchange failed", agentId, error);
|
|
47
|
+
}
|
|
48
|
+
return readProjection(paseo, agentId, "canonical");
|
|
49
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Which workspaces currently have a mounted Workspace Inbox panel (011).
|
|
5
|
+
*
|
|
6
|
+
* Inactive tabs and a collapsed Explorer stay mounted. The host can still
|
|
7
|
+
* evict an inactive tab after its retained-tab limit is reached.
|
|
8
|
+
*/
|
|
9
|
+
const mounted = new Map<string, Set<object>>();
|
|
10
|
+
const listeners = new Set<(workspaceId: string) => void>();
|
|
11
|
+
|
|
12
|
+
export function setPanelMounted(workspaceId: string, instance: object, isMounted: boolean): void {
|
|
13
|
+
const instances = mounted.get(workspaceId);
|
|
14
|
+
const was = instances != null && instances.size > 0;
|
|
15
|
+
if (isMounted) {
|
|
16
|
+
if (instances) instances.add(instance);
|
|
17
|
+
else mounted.set(workspaceId, new Set([instance]));
|
|
18
|
+
} else if (instances) {
|
|
19
|
+
instances.delete(instance);
|
|
20
|
+
if (instances.size === 0) mounted.delete(workspaceId);
|
|
21
|
+
}
|
|
22
|
+
if (was === isPanelMounted(workspaceId)) return;
|
|
23
|
+
for (const listener of listeners) listener(workspaceId);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function isPanelMounted(workspaceId: string): boolean {
|
|
27
|
+
return (mounted.get(workspaceId)?.size ?? 0) > 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Called with the workspace id whenever its mounted state flips. */
|
|
31
|
+
export function watchPanelPresence(listener: (workspaceId: string) => void): () => void {
|
|
32
|
+
listeners.add(listener);
|
|
33
|
+
return () => {
|
|
34
|
+
listeners.delete(listener);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Registers a panel until unmount or workspace change. */
|
|
39
|
+
export function usePanelPresenceReport(workspaceId: string): void {
|
|
40
|
+
const instance = useRef({}).current;
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
setPanelMounted(workspaceId, instance, true);
|
|
43
|
+
return () => setPanelMounted(workspaceId, instance, false);
|
|
44
|
+
}, [workspaceId, instance]);
|
|
45
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** Tags a new note gets when it is first saved. */
|
|
2
|
+
export interface DraftTags {
|
|
3
|
+
/** Tag this workspace and its project. */
|
|
4
|
+
workspaceId?: string;
|
|
5
|
+
/** Tag only this workspace's project. */
|
|
6
|
+
projectOfWorkspace?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** What the Inbox surface should open next; set by commands before `openSurface`. */
|
|
10
|
+
export type SelectionRequest = { itemId: string } | { draft: DraftTags };
|
|
11
|
+
|
|
12
|
+
let pending: SelectionRequest | null = null;
|
|
13
|
+
const listeners = new Set<() => void>();
|
|
14
|
+
|
|
15
|
+
function request(next: SelectionRequest): void {
|
|
16
|
+
pending = next;
|
|
17
|
+
for (const listener of listeners) listener();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function requestSelection(itemId: string): void {
|
|
21
|
+
request({ itemId });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Opens an unsaved note; nothing is stored until it has a title or body. */
|
|
25
|
+
export function requestDraft(draft: DraftTags = {}): void {
|
|
26
|
+
request({ draft });
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function takeSelection(): SelectionRequest | null {
|
|
30
|
+
const next = pending;
|
|
31
|
+
pending = null;
|
|
32
|
+
return next;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function onSelectionRequest(listener: () => void): () => void {
|
|
36
|
+
listeners.add(listener);
|
|
37
|
+
return () => listeners.delete(listener);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const changeListeners = new Set<() => void>();
|
|
41
|
+
|
|
42
|
+
/** Commands that write without opening the Inbox call this so mounted lists refetch. */
|
|
43
|
+
export function notifyItemsChanged(): void {
|
|
44
|
+
for (const listener of changeListeners) listener();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function onItemsChanged(listener: () => void): () => void {
|
|
48
|
+
changeListeners.add(listener);
|
|
49
|
+
return () => changeListeners.delete(listener);
|
|
50
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { useSettings } from "@getpaseo/plugin/client";
|
|
2
|
+
import { useToast } from "@getpaseo/plugin/client/react-native";
|
|
3
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
import {
|
|
5
|
+
INBOX_FILTER_DEFAULTS,
|
|
6
|
+
inboxFilterSettings,
|
|
7
|
+
sameInboxFilters,
|
|
8
|
+
type InboxFilters,
|
|
9
|
+
} from "../shared/filter-settings.ts";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The last kind / workspace / project selection, stored in host settings.
|
|
13
|
+
* A click updates the chips immediately and writes the full document.
|
|
14
|
+
*/
|
|
15
|
+
export function useInboxFilters(): {
|
|
16
|
+
values: InboxFilters | null;
|
|
17
|
+
update: (patch: Partial<InboxFilters>) => void;
|
|
18
|
+
} {
|
|
19
|
+
const settings = useSettings(inboxFilterSettings);
|
|
20
|
+
const toast = useToast();
|
|
21
|
+
const [patch, setPatch] = useState<Partial<InboxFilters>>({});
|
|
22
|
+
const patchRef = useRef(patch);
|
|
23
|
+
patchRef.current = patch;
|
|
24
|
+
const wasSaving = useRef(false);
|
|
25
|
+
const writeId = useRef(0);
|
|
26
|
+
const prevStatus = useRef(settings.status);
|
|
27
|
+
const toasted = useRef<string | null>(null);
|
|
28
|
+
|
|
29
|
+
const beginWrite = () => {
|
|
30
|
+
writeId.current += 1;
|
|
31
|
+
return writeId.current;
|
|
32
|
+
};
|
|
33
|
+
const endWrite = (id: number) => {
|
|
34
|
+
if (writeId.current === id) writeId.current = 0;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const saved = settings.status === "ready" ? settings.values : null;
|
|
38
|
+
const values = useMemo(() => {
|
|
39
|
+
if (saved) return Object.keys(patch).length === 0 ? saved : { ...saved, ...patch };
|
|
40
|
+
if (settings.status === "loading") {
|
|
41
|
+
return Object.keys(patch).length === 0 ? null : { ...INBOX_FILTER_DEFAULTS, ...patch };
|
|
42
|
+
}
|
|
43
|
+
return { ...INBOX_FILTER_DEFAULTS, ...patch };
|
|
44
|
+
}, [patch, saved, settings.status]);
|
|
45
|
+
|
|
46
|
+
const update = (next: Partial<InboxFilters>) => {
|
|
47
|
+
const merged = { ...patchRef.current, ...next };
|
|
48
|
+
patchRef.current = merged;
|
|
49
|
+
setPatch(merged);
|
|
50
|
+
if (settings.status !== "ready" || settings.saving || writeId.current !== 0) return;
|
|
51
|
+
const id = beginWrite();
|
|
52
|
+
void settings.save({ ...settings.values, ...merged }, settings.revision).finally(() => endWrite(id));
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (settings.saveError && toasted.current !== settings.saveError) {
|
|
57
|
+
toasted.current = settings.saveError;
|
|
58
|
+
toast.error(settings.saveError);
|
|
59
|
+
}
|
|
60
|
+
if (!settings.saveError) toasted.current = null;
|
|
61
|
+
|
|
62
|
+
const becameReady = prevStatus.current !== "ready" && settings.status === "ready";
|
|
63
|
+
const finishedSave = wasSaving.current && !settings.saving;
|
|
64
|
+
prevStatus.current = settings.status;
|
|
65
|
+
wasSaving.current = settings.saving;
|
|
66
|
+
if (settings.status !== "ready" || settings.saving || settings.saveError) return;
|
|
67
|
+
if (writeId.current !== 0 && !finishedSave) return;
|
|
68
|
+
|
|
69
|
+
const pending = patchRef.current;
|
|
70
|
+
if (Object.keys(pending).length === 0) return;
|
|
71
|
+
const next = { ...settings.values, ...pending };
|
|
72
|
+
if (sameInboxFilters(next, settings.values)) {
|
|
73
|
+
patchRef.current = {};
|
|
74
|
+
setPatch({});
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (!becameReady && !finishedSave) return;
|
|
78
|
+
const id = beginWrite();
|
|
79
|
+
void settings.save(next, settings.revision).finally(() => endWrite(id));
|
|
80
|
+
}, [settings, toast]);
|
|
81
|
+
|
|
82
|
+
return { values, update };
|
|
83
|
+
}
|
package/client/web.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-only helpers. Callers must check `Platform.OS === "web"` first.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
interface DragEvent {
|
|
6
|
+
pageX: number;
|
|
7
|
+
preventDefault(): void;
|
|
8
|
+
}
|
|
9
|
+
interface DomWindow {
|
|
10
|
+
addEventListener(type: string, listener: (event: DragEvent) => void): void;
|
|
11
|
+
removeEventListener(type: string, listener: (event: DragEvent) => void): void;
|
|
12
|
+
}
|
|
13
|
+
declare const window: DomWindow;
|
|
14
|
+
declare const document: { body: { style: { cursor: string; userSelect: string } } };
|
|
15
|
+
declare function requestAnimationFrame(callback: () => void): number;
|
|
16
|
+
declare function cancelAnimationFrame(handle: number): void;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Follows a horizontal drag on `window`, so it keeps tracking after the pointer
|
|
20
|
+
* leaves the handle. `onMove` receives the offset from `startX`, at most once per frame.
|
|
21
|
+
*/
|
|
22
|
+
export function trackHorizontalDrag(
|
|
23
|
+
startX: number,
|
|
24
|
+
onMove: (dx: number) => void,
|
|
25
|
+
): void {
|
|
26
|
+
const body = document.body.style;
|
|
27
|
+
const previous = { cursor: body.cursor, userSelect: body.userSelect };
|
|
28
|
+
body.cursor = "col-resize";
|
|
29
|
+
body.userSelect = "none";
|
|
30
|
+
|
|
31
|
+
let frame = 0;
|
|
32
|
+
let lastX = startX;
|
|
33
|
+
const move = (event: DragEvent) => {
|
|
34
|
+
event.preventDefault();
|
|
35
|
+
lastX = event.pageX;
|
|
36
|
+
if (frame) return;
|
|
37
|
+
frame = requestAnimationFrame(() => {
|
|
38
|
+
frame = 0;
|
|
39
|
+
onMove(lastX - startX);
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
const end = () => {
|
|
43
|
+
window.removeEventListener("mousemove", move);
|
|
44
|
+
window.removeEventListener("mouseup", end);
|
|
45
|
+
window.removeEventListener("blur", end);
|
|
46
|
+
if (frame) cancelAnimationFrame(frame);
|
|
47
|
+
onMove(lastX - startX);
|
|
48
|
+
body.cursor = previous.cursor;
|
|
49
|
+
body.userSelect = previous.userSelect;
|
|
50
|
+
};
|
|
51
|
+
window.addEventListener("mousemove", move);
|
|
52
|
+
window.addEventListener("mouseup", end);
|
|
53
|
+
window.addEventListener("blur", end);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface WheelEvent {
|
|
57
|
+
deltaX: number;
|
|
58
|
+
deltaY: number;
|
|
59
|
+
preventDefault(): void;
|
|
60
|
+
}
|
|
61
|
+
export interface HorizontalScrollNode {
|
|
62
|
+
scrollLeft: number;
|
|
63
|
+
scrollWidth: number;
|
|
64
|
+
clientWidth: number;
|
|
65
|
+
addEventListener(type: "wheel", listener: (event: WheelEvent) => void, options: { passive: boolean }): void;
|
|
66
|
+
removeEventListener(type: "wheel", listener: (event: WheelEvent) => void): void;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Lets a vertical mouse wheel scroll a horizontal strip. At either end the
|
|
71
|
+
* event is left alone so the surrounding page keeps scrolling. Returns cleanup.
|
|
72
|
+
*/
|
|
73
|
+
export function wheelScrollsHorizontally(node: HorizontalScrollNode): () => void {
|
|
74
|
+
const onWheel = (event: WheelEvent) => {
|
|
75
|
+
if (Math.abs(event.deltaX) >= Math.abs(event.deltaY)) return;
|
|
76
|
+
const max = node.scrollWidth - node.clientWidth;
|
|
77
|
+
const next = Math.max(0, Math.min(max, node.scrollLeft + event.deltaY));
|
|
78
|
+
if (next === node.scrollLeft) return;
|
|
79
|
+
event.preventDefault();
|
|
80
|
+
node.scrollLeft = next;
|
|
81
|
+
};
|
|
82
|
+
node.addEventListener("wheel", onWheel, { passive: false });
|
|
83
|
+
return () => node.removeEventListener("wheel", onWheel);
|
|
84
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type PluginWorkspacePanelProps, useWorkspace } from "@getpaseo/plugin/client";
|
|
2
|
+
import { Text, View } from "react-native";
|
|
3
|
+
import { InboxView } from "./inbox-surface.tsx";
|
|
4
|
+
import { usePanelPresenceReport } from "./panel-visibility.ts";
|
|
5
|
+
|
|
6
|
+
/** Explorer panel: the Inbox of one workspace. */
|
|
7
|
+
export function WorkspaceInboxPanel({ theme, layout, navigation, workspaceId }: PluginWorkspacePanelProps) {
|
|
8
|
+
usePanelPresenceReport(workspaceId);
|
|
9
|
+
const workspace = useWorkspace(workspaceId, ({ id, directory }) => ({ id, directory }));
|
|
10
|
+
if (!workspace) {
|
|
11
|
+
return (
|
|
12
|
+
<View style={{ flex: 1, padding: 16, backgroundColor: theme.colors.surface0 }}>
|
|
13
|
+
<Text style={{ color: theme.colors.foregroundMuted, fontSize: 12 }}>Workspace unavailable.</Text>
|
|
14
|
+
</View>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
return <InboxView theme={theme} layout={layout} navigation={navigation} workspace={workspace} />;
|
|
18
|
+
}
|
package/index.client.tsx
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { PluginClientContext } from "@getpaseo/plugin/client";
|
|
2
|
+
import { contributeHeaderButtons } from "./client/header-button.ts";
|
|
3
|
+
import { InboxSurface } from "./client/inbox-surface.tsx";
|
|
4
|
+
import { notifyItemsChanged, requestDraft, requestSelection } from "./client/selection.ts";
|
|
5
|
+
import { WorkspaceInboxPanel } from "./client/workspace-panel.tsx";
|
|
6
|
+
import { saveNote, starAgent } from "./shared/contracts.ts";
|
|
7
|
+
import { parseInboxCommand } from "./shared/slash-command.ts";
|
|
8
|
+
|
|
9
|
+
const SURFACE = "inbox";
|
|
10
|
+
|
|
11
|
+
export default function contribute(client: PluginClientContext) {
|
|
12
|
+
const removers = [
|
|
13
|
+
client.addSurface(SURFACE, InboxSurface),
|
|
14
|
+
client.addSidebarItem({ id: SURFACE, title: "Inbox", icon: "Inbox", surface: SURFACE }),
|
|
15
|
+
client.addWorkspacePanel({
|
|
16
|
+
id: "workspace-inbox",
|
|
17
|
+
title: "Inbox",
|
|
18
|
+
icon: "Inbox",
|
|
19
|
+
context: "workspace",
|
|
20
|
+
locations: ["explorer"],
|
|
21
|
+
Component: WorkspaceInboxPanel,
|
|
22
|
+
}),
|
|
23
|
+
client.addCommandCenterItem({
|
|
24
|
+
id: "open",
|
|
25
|
+
title: "Inbox",
|
|
26
|
+
icon: "Inbox",
|
|
27
|
+
keywords: ["open"],
|
|
28
|
+
context: "global",
|
|
29
|
+
onSelect: ({ openSurface }) => openSurface(SURFACE),
|
|
30
|
+
}),
|
|
31
|
+
client.addCommandCenterItem({
|
|
32
|
+
id: "star-agent",
|
|
33
|
+
title: "Add agent to Inbox",
|
|
34
|
+
icon: "Star",
|
|
35
|
+
keywords: ["star", "favorite", "bookmark", "inbox"],
|
|
36
|
+
context: "agent",
|
|
37
|
+
async onSelect({ agent, rpc, openSurface }) {
|
|
38
|
+
const { item } = await rpc(starAgent, { agentId: agent.id });
|
|
39
|
+
requestSelection(item.id);
|
|
40
|
+
openSurface(SURFACE);
|
|
41
|
+
},
|
|
42
|
+
}),
|
|
43
|
+
client.addCommandCenterItem({
|
|
44
|
+
id: "quick-note",
|
|
45
|
+
title: "New Inbox note",
|
|
46
|
+
icon: "NotebookPen",
|
|
47
|
+
keywords: ["note", "inbox", "capture"],
|
|
48
|
+
context: "workspace",
|
|
49
|
+
onSelect({ workspace, openSurface }) {
|
|
50
|
+
requestDraft({ projectOfWorkspace: workspace.id });
|
|
51
|
+
openSurface(SURFACE);
|
|
52
|
+
},
|
|
53
|
+
}),
|
|
54
|
+
client.addSlashCommand({
|
|
55
|
+
name: "inbox",
|
|
56
|
+
description: "Add this agent to the Inbox, or save text as a scratch note tagged with this project.",
|
|
57
|
+
argumentHint: "[text]",
|
|
58
|
+
context: "agent",
|
|
59
|
+
async onSubmit({ args, agent, workspace, rpc }) {
|
|
60
|
+
const command = parseInboxCommand(args);
|
|
61
|
+
if (!command.text) {
|
|
62
|
+
await rpc(starAgent, { agentId: agent.id });
|
|
63
|
+
} else {
|
|
64
|
+
await rpc(saveNote, { kind: "scratch", body: command.text, projectOfWorkspace: workspace.id });
|
|
65
|
+
}
|
|
66
|
+
notifyItemsChanged();
|
|
67
|
+
},
|
|
68
|
+
}),
|
|
69
|
+
contributeHeaderButtons(client),
|
|
70
|
+
];
|
|
71
|
+
return () => {
|
|
72
|
+
for (const remove of removers) remove();
|
|
73
|
+
};
|
|
74
|
+
}
|
package/index.server.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { PluginServerContext } from "@getpaseo/plugin/server";
|
|
2
|
+
import { createDaemonConnection } from "./server/daemon.ts";
|
|
3
|
+
import { registerHandlers } from "./server/handlers.ts";
|
|
4
|
+
import { createProjectResolver } from "./server/project-key.ts";
|
|
5
|
+
import { InboxStore } from "./server/store.ts";
|
|
6
|
+
import { inboxFilterSettings } from "./shared/filter-settings.ts";
|
|
7
|
+
|
|
8
|
+
export default function contribute(server: PluginServerContext) {
|
|
9
|
+
server.registerSettings(inboxFilterSettings);
|
|
10
|
+
const store = new InboxStore();
|
|
11
|
+
const daemon = createDaemonConnection();
|
|
12
|
+
registerHandlers(server, { store, resolveProject: createProjectResolver(), daemon });
|
|
13
|
+
return async () => {
|
|
14
|
+
await daemon.close();
|
|
15
|
+
store.close();
|
|
16
|
+
};
|
|
17
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@koinzhang/paseo-plugin-inbox",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Personal inbox for Paseo: star agents, keep notes per project, and capture scratch text.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/koinzhang/paseo-plugins.git",
|
|
10
|
+
"directory": "inbox"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"paseo-plugin.json",
|
|
14
|
+
"CHANGELOG.md",
|
|
15
|
+
"index.client.tsx",
|
|
16
|
+
"index.server.ts",
|
|
17
|
+
"client/",
|
|
18
|
+
"server/",
|
|
19
|
+
"shared/",
|
|
20
|
+
"!**/*.test.ts",
|
|
21
|
+
"LICENSE",
|
|
22
|
+
"README.md"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"typecheck": "tsc --noEmit",
|
|
26
|
+
"test": "node --experimental-strip-types --test shared/*.test.ts server/*.test.ts client/*.test.ts"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@getpaseo/client": "0.9.2",
|
|
30
|
+
"ws": "^8.18.3"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@getpaseo/plugin": "0.9.2",
|
|
34
|
+
"@tanstack/react-query": "^5.90.11",
|
|
35
|
+
"@types/node": "^24.13.5",
|
|
36
|
+
"@types/react": "~19.2.0",
|
|
37
|
+
"@types/ws": "^8.18.1",
|
|
38
|
+
"react": "19.1.0",
|
|
39
|
+
"react-native": "0.81.5",
|
|
40
|
+
"typescript": "^5.9.3",
|
|
41
|
+
"zod": "^4.6.5"
|
|
42
|
+
}
|
|
43
|
+
}
|
package/server/agents.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { DaemonClient } from "@getpaseo/client/internal/daemon-client";
|
|
2
|
+
import type { PaseoApi } from "@getpaseo/client";
|
|
3
|
+
import type { AgentCandidate, AgentLive, AgentSnapshot, AgentState } from "../shared/contracts.ts";
|
|
4
|
+
|
|
5
|
+
const PAGE_LIMIT = 200;
|
|
6
|
+
const MAX_PAGES = 100;
|
|
7
|
+
|
|
8
|
+
export interface AgentLookup {
|
|
9
|
+
snapshot: AgentSnapshot;
|
|
10
|
+
archived: boolean;
|
|
11
|
+
live: AgentLive;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function liveAttention(agent: {
|
|
15
|
+
pendingPermissions?: ReadonlyArray<unknown>;
|
|
16
|
+
requiresAttention?: boolean;
|
|
17
|
+
attentionReason?: string | null;
|
|
18
|
+
}): AgentLive["attention"] {
|
|
19
|
+
if ((agent.pendingPermissions?.length ?? 0) > 0) return "permission";
|
|
20
|
+
if (!agent.requiresAttention) return null;
|
|
21
|
+
const reason = agent.attentionReason;
|
|
22
|
+
return reason === "finished" || reason === "error" || reason === "permission" ? reason : null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Reads an agent through the public SDK; null when the daemon no longer knows it. */
|
|
26
|
+
export async function lookupAgent(paseo: PaseoApi, agentId: string): Promise<AgentLookup | null> {
|
|
27
|
+
let result;
|
|
28
|
+
try {
|
|
29
|
+
result = await paseo.agents.ref(agentId).refresh();
|
|
30
|
+
} catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
if (!result) return null;
|
|
34
|
+
const { agent } = result;
|
|
35
|
+
return {
|
|
36
|
+
snapshot: {
|
|
37
|
+
title: agent.title,
|
|
38
|
+
provider: agent.provider,
|
|
39
|
+
model: agent.model,
|
|
40
|
+
workspaceId: agent.workspaceId ?? null,
|
|
41
|
+
cwd: agent.cwd,
|
|
42
|
+
createdAt: agent.createdAt,
|
|
43
|
+
},
|
|
44
|
+
archived: Boolean(agent.archivedAt),
|
|
45
|
+
live: {
|
|
46
|
+
status: agent.status,
|
|
47
|
+
attention: liveAttention(agent),
|
|
48
|
+
permissions: agent.pendingPermissions?.length ?? 0,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export async function agentState(
|
|
54
|
+
paseo: PaseoApi,
|
|
55
|
+
agentId: string,
|
|
56
|
+
): Promise<{ state: AgentState; live: AgentLive | null; title: string | null }> {
|
|
57
|
+
const found = await lookupAgent(paseo, agentId);
|
|
58
|
+
if (!found) return { state: "missing", live: null, title: null };
|
|
59
|
+
return { state: found.archived ? "archived" : "active", live: found.live, title: found.snapshot.title };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Unarchived agents of one workspace. */
|
|
63
|
+
export async function workspaceAgents(paseo: PaseoApi, workspaceId: string): Promise<AgentCandidate[]> {
|
|
64
|
+
const agents: AgentCandidate[] = [];
|
|
65
|
+
let cursor: string | undefined;
|
|
66
|
+
for (let pages = 0; pages < MAX_PAGES; pages++) {
|
|
67
|
+
const page = await paseo.agents.list({
|
|
68
|
+
page: { limit: PAGE_LIMIT, ...(cursor ? { cursor } : {}) },
|
|
69
|
+
});
|
|
70
|
+
for (const { agent } of page.entries) {
|
|
71
|
+
if (agent.workspaceId !== workspaceId || agent.archivedAt) continue;
|
|
72
|
+
agents.push({ id: agent.id, title: agent.title, provider: agent.provider });
|
|
73
|
+
}
|
|
74
|
+
if (!page.pageInfo.hasMore || !page.pageInfo.nextCursor) break;
|
|
75
|
+
cursor = page.pageInfo.nextCursor;
|
|
76
|
+
}
|
|
77
|
+
return agents;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Unarchives an agent the way the app does, restoring its archived workspace first.
|
|
82
|
+
* The public SDK has no unarchive, so this uses the internal daemon client.
|
|
83
|
+
*/
|
|
84
|
+
export async function unarchiveAgent(
|
|
85
|
+
client: DaemonClient,
|
|
86
|
+
agentId: string,
|
|
87
|
+
): Promise<{ restoredWorkspace: boolean }> {
|
|
88
|
+
const fetched = await client.fetchAgent(agentId);
|
|
89
|
+
if (!fetched) throw new Error("This agent no longer exists on the host");
|
|
90
|
+
|
|
91
|
+
let restoredWorkspace = false;
|
|
92
|
+
const workspaceId = fetched.agent.workspaceId;
|
|
93
|
+
const supportsRecovery = client.getLastServerInfoMessage()?.features?.workspaceRecovery === true;
|
|
94
|
+
if (workspaceId && supportsRecovery) {
|
|
95
|
+
const recovery = await client.inspectWorkspaceRecovery(workspaceId);
|
|
96
|
+
if (recovery.kind === "recoverable") {
|
|
97
|
+
await client.restoreWorkspace(workspaceId);
|
|
98
|
+
restoredWorkspace = true;
|
|
99
|
+
} else if (recovery.reason !== "workspace_not_archived") {
|
|
100
|
+
throw new Error(recovery.message);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
await client.refreshAgent(agentId);
|
|
105
|
+
return { restoredWorkspace };
|
|
106
|
+
}
|
package/server/daemon.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { DaemonClient, type WebSocketLike } from "@getpaseo/client/internal/daemon-client";
|
|
5
|
+
import WebSocket from "ws";
|
|
6
|
+
|
|
7
|
+
interface DaemonTarget {
|
|
8
|
+
url: string;
|
|
9
|
+
socketPath?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function paseoHome(): string {
|
|
13
|
+
const raw = process.env.PASEO_HOME ?? "~/.paseo";
|
|
14
|
+
return path.resolve(raw.startsWith("~") ? path.join(homedir(), raw.slice(1)) : raw);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Mirrors the listen forms the daemon accepts: host:port, /path, unix:///path. */
|
|
18
|
+
export function toDaemonTarget(listen: string): DaemonTarget {
|
|
19
|
+
const trimmed = listen.trim();
|
|
20
|
+
const socketPath = trimmed.startsWith("unix://")
|
|
21
|
+
? trimmed.slice("unix://".length)
|
|
22
|
+
: trimmed.startsWith("/")
|
|
23
|
+
? trimmed
|
|
24
|
+
: null;
|
|
25
|
+
if (socketPath) return { url: `ws+unix://${socketPath}:/ws`, socketPath };
|
|
26
|
+
const endpoint = /^\d+$/.test(trimmed) ? `127.0.0.1:${trimmed}` : trimmed;
|
|
27
|
+
return { url: `ws://${endpoint}/ws` };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function resolveListen(): Promise<string> {
|
|
31
|
+
if (process.env.PASEO_LISTEN) return process.env.PASEO_LISTEN;
|
|
32
|
+
try {
|
|
33
|
+
const pid = JSON.parse(await readFile(path.join(paseoHome(), "paseo.pid"), "utf8")) as {
|
|
34
|
+
listen?: unknown;
|
|
35
|
+
};
|
|
36
|
+
if (typeof pid.listen === "string" && pid.listen) return pid.listen;
|
|
37
|
+
} catch {
|
|
38
|
+
// Fall through to the daemon default.
|
|
39
|
+
}
|
|
40
|
+
return `127.0.0.1:${process.env.PORT ?? "6767"}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function connect(): Promise<DaemonClient> {
|
|
44
|
+
const target = toDaemonTarget(await resolveListen());
|
|
45
|
+
const client = new DaemonClient({
|
|
46
|
+
url: target.url,
|
|
47
|
+
clientId: `inbox-plugin-${process.pid}`,
|
|
48
|
+
clientType: "cli",
|
|
49
|
+
password: process.env.PASEO_PASSWORD || undefined,
|
|
50
|
+
connectTimeoutMs: 5_000,
|
|
51
|
+
reconnect: { enabled: true },
|
|
52
|
+
webSocketFactory: (url, options) =>
|
|
53
|
+
new WebSocket(url, options?.protocols, {
|
|
54
|
+
headers: options?.headers,
|
|
55
|
+
...(target.socketPath ? { socketPath: target.socketPath } : {}),
|
|
56
|
+
}) as unknown as WebSocketLike,
|
|
57
|
+
});
|
|
58
|
+
try {
|
|
59
|
+
await client.connect();
|
|
60
|
+
return client;
|
|
61
|
+
} catch (error) {
|
|
62
|
+
await client.close().catch(() => {});
|
|
63
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
64
|
+
throw new Error(`Cannot reach the Paseo daemon at ${target.url}: ${message}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** One lazily opened connection per plugin process, reopened after a failure. */
|
|
69
|
+
export function createDaemonConnection() {
|
|
70
|
+
let pending: Promise<DaemonClient> | null = null;
|
|
71
|
+
return {
|
|
72
|
+
get(): Promise<DaemonClient> {
|
|
73
|
+
pending ??= connect().catch((error: unknown) => {
|
|
74
|
+
pending = null;
|
|
75
|
+
throw error;
|
|
76
|
+
});
|
|
77
|
+
return pending;
|
|
78
|
+
},
|
|
79
|
+
async close(): Promise<void> {
|
|
80
|
+
const current = pending;
|
|
81
|
+
pending = null;
|
|
82
|
+
if (current) await (await current.catch(() => null))?.close();
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|