Initial commit: group-by-host Paseo sidebar plugin

This commit is contained in:
nandi committed 2026-11-18 22:27:11 +00:00
commit dcfe97a2e6
13 files changed
+6789

No files matched your search

+758
View File
@@ -0,0 +1,758 @@
import type { PluginTheme } from "@getpaseo/plugin";
import type { AgentRef, WorkspaceRef } from "@getpaseo/plugin/client";
import { useAgent, usePaseo, useWorkspace } from "@getpaseo/plugin/client";
import { copyText, Icon, useToast } from "@getpaseo/plugin/client/ui";
import { useMemo, useState } from "react";
import { Pressable, Text, View } from "react-native";
import {
type ContextMenuRequest,
useContextMenuTarget,
} from "./context-menu";
import {
getAgentStatusColor,
getAgentSubtitle,
getWorkspaceIndicatorColor,
} from "./grouping";
import {
ActionPill,
ConfirmArchiveModal,
RenameWorkspaceModal,
RowIconButton,
} from "./workspace-actions";
interface AgentRowProps {
agentRef: AgentRef;
theme: PluginTheme;
platform: "ios" | "android" | "web";
isActive: boolean;
actionsOpen: boolean;
onToggleActions(key: string): void;
onCloseActions(): void;
onOpenContextMenu(request: ContextMenuRequest): void;
onOpenAgent(ref: AgentRef): void;
}
function AgentRow({
agentRef,
theme,
platform,
isActive,
actionsOpen,
onToggleActions,
onCloseActions,
onOpenContextMenu,
onOpenAgent,
}: AgentRowProps) {
const agent = useAgent(agentRef);
const paseo = usePaseo();
const toast = useToast();
const [archiveOpen, setArchiveOpen] = useState(false);
const [busy, setBusy] = useState(false);
const contextMenuRef = useContextMenuTarget(openContextMenu);
if (!agent) return null;
const dotColor = getAgentStatusColor(agent, theme);
const label = agent.title?.trim() || agent.provider;
const subtitle = getAgentSubtitle(agent);
const menuKey = `agent:${agent.ref.key}`;
function openContextMenu(clientX: number, clientY: number) {
if (!agent) return;
onOpenContextMenu({
clientX,
clientY,
title: label,
items: [
{
id: "open",
icon: "ExternalLink",
label: "Open agent",
onSelect: () => onOpenAgent(agent.ref),
},
{
id: "copy-id",
icon: "Copy",
label: "Copy ID",
disabled: busy,
onSelect: () => handleCopy(agent.id, "Copied agent ID"),
},
{
id: "copy-cwd",
icon: "Copy",
label: "Copy CWD",
disabled: busy,
onSelect: () => handleCopy(agent.cwd, "Copied working directory"),
},
{
id: "archive",
icon: "Archive",
label: "Archive",
tone: "danger",
disabled: busy,
separatorBefore: true,
onSelect: () => setArchiveOpen(true),
},
],
});
}
async function handleCopy(value: string, successMessage: string) {
try {
await copyText(value);
toast.show(successMessage, { variant: "success" });
onCloseActions();
} catch (error) {
toast.error(error instanceof Error ? error.message : "Failed to copy");
}
}
async function handleArchiveAgent() {
if (!agent || busy) return;
setBusy(true);
try {
await paseo.agents.ref(agent.ref).archive();
setArchiveOpen(false);
toast.show(`Archived ${label}`, { variant: "success" });
onCloseActions();
} catch (error) {
toast.error(
error instanceof Error ? error.message : "Failed to archive agent",
);
} finally {
setBusy(false);
}
}
return (
<View style={{ gap: 2 }}>
<View
ref={contextMenuRef as never}
style={{
flexDirection: "row",
alignItems: "flex-start",
borderRadius: 6,
backgroundColor: isActive ? theme.colors.surface2 : "transparent",
}}
>
<Pressable
accessibilityRole="button"
accessibilityLabel={`Open agent ${label}`}
onPress={() => onOpenAgent(agent.ref)}
onLongPress={
platform !== "web" ? () => openContextMenu(0, 0) : undefined
}
style={({ pressed }) => ({
flex: 1,
minWidth: 0,
flexDirection: "row",
alignItems: "flex-start",
gap: 8,
paddingVertical: 5,
paddingLeft: 26,
paddingRight: 4,
borderRadius: 6,
backgroundColor:
!isActive && pressed ? theme.colors.surface1 : "transparent",
})}
>
<View
style={{
width: 6,
height: 6,
borderRadius: 3,
marginTop: 5,
flexShrink: 0,
backgroundColor: dotColor,
}}
/>
<Text
style={{
flex: 1,
minWidth: 0,
fontSize: 12,
lineHeight: 16,
fontWeight: isActive || agent.requiresAttention ? "600" : "400",
color: isActive
? theme.colors.foreground
: theme.colors.foregroundMuted,
}}
>
{label}
</Text>
{subtitle ? (
<Text
numberOfLines={1}
style={{
flexShrink: 0,
maxWidth: 110,
fontSize: 11,
lineHeight: 16,
color: agent.requiresAttention
? dotColor
: theme.colors.foregroundMuted,
}}
>
{subtitle}
</Text>
) : null}
</Pressable>
<View
style={{
flexDirection: "row",
alignItems: "center",
alignSelf: "flex-start",
flexShrink: 0,
marginRight: 2,
}}
>
<RowIconButton
icon="Archive"
accessibilityLabel={`Archive agent ${label}`}
theme={theme}
size={12}
paddingVertical={5}
disabled={busy}
onPress={() => setArchiveOpen(true)}
/>
<RowIconButton
icon="MoreHorizontal"
accessibilityLabel={`Agent actions for ${label}`}
theme={theme}
size={13}
paddingVertical={5}
active={actionsOpen}
onPress={() => onToggleActions(menuKey)}
/>
</View>
</View>
{actionsOpen ? (
<View
style={{
flexDirection: "row",
flexWrap: "wrap",
gap: 6,
paddingLeft: 26,
paddingRight: 8,
paddingVertical: 4,
}}
>
<ActionPill
icon="Copy"
label="Copy ID"
theme={theme}
disabled={busy}
onPress={() => handleCopy(agent.id, "Copied agent ID")}
/>
<ActionPill
icon="Copy"
label="Copy CWD"
theme={theme}
disabled={busy}
onPress={() => handleCopy(agent.cwd, "Copied working directory")}
/>
<ActionPill
icon="Archive"
label="Archive"
theme={theme}
tone="danger"
disabled={busy}
onPress={() => setArchiveOpen(true)}
/>
</View>
) : null}
<ConfirmArchiveModal
open={archiveOpen}
title="Archive agent"
description={`Archive "${label}"? You can access archived agents later from history if needed.`}
theme={theme}
archiving={busy}
onClose={() => setArchiveOpen(false)}
onConfirm={handleArchiveAgent}
/>
</View>
);
}
export interface WorkspaceRowProps {
workspaceRef: WorkspaceRef;
agentRefs: readonly AgentRef[];
theme: PluginTheme;
compact: boolean;
platform: "ios" | "android" | "web";
showAgents: boolean;
activeWorkspaceKey: string | null;
activeAgentKey: string | null;
activeMenuKey: string | null;
onToggleMenu(key: string): void;
onCloseMenu(): void;
onOpenContextMenu(request: ContextMenuRequest): void;
onOpenWorkspace(ref: WorkspaceRef): void;
onOpenAgent(ref: AgentRef): void;
}
export function WorkspaceRow({
workspaceRef,
agentRefs,
theme,
compact,
platform,
showAgents,
activeWorkspaceKey,
activeAgentKey,
activeMenuKey,
onToggleMenu,
onCloseMenu,
onOpenContextMenu,
onOpenWorkspace,
onOpenAgent,
}: WorkspaceRowProps) {
const workspace = useWorkspace(workspaceRef);
const paseo = usePaseo();
const toast = useToast();
const [agentsCollapsed, setAgentsCollapsed] = useState(false);
const [renameOpen, setRenameOpen] = useState(false);
const [archiveOpen, setArchiveOpen] = useState(false);
const [busy, setBusy] = useState(false);
const contextMenuRef = useContextMenuTarget(openContextMenu);
const menuKey = `workspace:${workspaceRef.key}`;
const actionsOpen = activeMenuKey === menuKey;
const isActiveWorkspace = activeWorkspaceKey === workspaceRef.key;
const hasAgents = agentRefs.length > 0;
const agentsExpanded = showAgents && hasAgents && !agentsCollapsed;
const metaLine = useMemo(() => {
if (!workspace) return "";
const parts: string[] = [];
if (workspace.projectDisplayName) {
parts.push(workspace.projectDisplayName);
}
if (workspace.branch && workspace.branch !== workspace.name) {
parts.push(workspace.branch);
}
if (workspace.indicatorLabel) {
parts.push(workspace.indicatorLabel);
}
return parts.join(" · ");
}, [workspace]);
if (!workspace) return null;
const title = workspace.title?.trim() || workspace.name;
const indicatorColor = getWorkspaceIndicatorColor(workspace.indicator, theme);
const diffAdditions = workspace.diffStat?.additions ?? 0;
const diffDeletions = workspace.diffStat?.deletions ?? 0;
const hasDiff = diffAdditions > 0 || diffDeletions > 0;
async function handleTogglePin() {
if (!workspace || busy) return;
const nextPinned = workspace.pinnedAt === null;
setBusy(true);
try {
await paseo.workspaces.ref(workspace.ref).setPinned(nextPinned);
toast.show(nextPinned ? `Pinned ${title}` : `Unpinned ${title}`, {
variant: "success",
});
onCloseMenu();
} catch (error) {
toast.error(
error instanceof Error ? error.message : "Failed to update pin state",
);
} finally {
setBusy(false);
}
}
async function handleRename(nextTitle: string | null) {
if (!workspace || busy) return;
setBusy(true);
try {
await paseo.workspaces.ref(workspace.ref).setTitle(nextTitle);
setRenameOpen(false);
onCloseMenu();
toast.show(
nextTitle ? `Renamed to "${nextTitle}"` : "Reset workspace title",
{ variant: "success" },
);
} catch (error) {
toast.error(
error instanceof Error ? error.message : "Failed to rename workspace",
);
} finally {
setBusy(false);
}
}
async function handleCopyDirectory() {
if (!workspace) return;
try {
await copyText(workspace.directory);
toast.show("Copied workspace directory", { variant: "success" });
onCloseMenu();
} catch (error) {
toast.error(error instanceof Error ? error.message : "Failed to copy");
}
}
async function handleArchiveWorkspace() {
if (!workspace || busy) return;
setBusy(true);
try {
const result = await paseo.workspaces.ref(workspace.ref).archive();
if (result.error) {
toast.error(result.error);
return;
}
setArchiveOpen(false);
toast.show(`Archived ${title}`, { variant: "success" });
onCloseMenu();
} catch (error) {
toast.error(
error instanceof Error ? error.message : "Failed to archive workspace",
);
} finally {
setBusy(false);
}
}
function openContextMenu(clientX: number, clientY: number) {
if (!workspace) return;
onOpenContextMenu({
clientX,
clientY,
title,
items: [
{
id: "open",
icon: "ExternalLink",
label: "Open workspace",
onSelect: () => onOpenWorkspace(workspace.ref),
},
{
id: "rename",
icon: "Pencil",
label: "Rename",
disabled: busy,
onSelect: () => setRenameOpen(true),
},
{
id: "pin",
icon: workspace.pinnedAt ? "PinOff" : "Pin",
label: workspace.pinnedAt ? "Unpin" : "Pin",
disabled: busy,
onSelect: handleTogglePin,
},
{
id: "copy-path",
icon: "Copy",
label: "Copy path",
disabled: busy,
onSelect: handleCopyDirectory,
},
{
id: "archive",
icon: "Archive",
label: "Archive",
tone: "danger",
disabled: busy,
separatorBefore: true,
onSelect: () => setArchiveOpen(true),
},
],
});
}
return (
<View style={{ gap: 2 }}>
<View
ref={contextMenuRef as never}
style={{
flexDirection: "row",
alignItems: "flex-start",
borderRadius: 8,
backgroundColor: isActiveWorkspace
? theme.colors.surface2
: "transparent",
}}
>
<Pressable
accessibilityRole="button"
accessibilityLabel={`Open workspace ${title}`}
onPress={() => onOpenWorkspace(workspace.ref)}
onLongPress={
platform !== "web" ? () => openContextMenu(0, 0) : undefined
}
style={({ pressed }) => ({
flex: 1,
minWidth: 0,
flexDirection: "row",
alignItems: "flex-start",
gap: 8,
paddingVertical: compact ? 8 : 6,
paddingLeft: 10,
paddingRight: 4,
borderRadius: 8,
backgroundColor:
!isActiveWorkspace && pressed
? theme.colors.surface1
: "transparent",
})}
>
<View
style={{
width: 8,
height: 8,
borderRadius: 4,
marginTop: 5,
flexShrink: 0,
backgroundColor: indicatorColor ?? theme.colors.border,
}}
/>
<View style={{ flex: 1, minWidth: 0, gap: 2 }}>
<View
style={{
flexDirection: "row",
alignItems: "flex-start",
gap: 5,
minWidth: 0,
}}
>
<Text
style={{
flex: 1,
minWidth: 0,
fontSize: 13,
lineHeight: 18,
fontWeight: isActiveWorkspace ? "600" : "500",
color: theme.colors.foreground,
}}
>
{title}
</Text>
{workspace.pinnedAt ? (
<View style={{ marginTop: 3, flexShrink: 0 }}>
<Icon
name="Pin"
size={11}
color={theme.colors.foregroundMuted}
/>
</View>
) : null}
{hasDiff ? (
<View
style={{
flexDirection: "row",
alignItems: "center",
gap: 3,
marginTop: 2,
flexShrink: 0,
}}
>
{diffAdditions > 0 ? (
<Text
style={{
fontSize: 11,
fontWeight: "500",
color: theme.colors.statusSuccess,
}}
>
+{diffAdditions}
</Text>
) : null}
{diffDeletions > 0 ? (
<Text
style={{
fontSize: 11,
fontWeight: "500",
color: theme.colors.statusDanger,
}}
>
-{diffDeletions}
</Text>
) : null}
</View>
) : null}
</View>
{metaLine ? (
<Text
style={{
fontSize: 11,
lineHeight: 15,
color: indicatorColor ?? theme.colors.foregroundMuted,
}}
>
{metaLine}
</Text>
) : null}
</View>
</Pressable>
<View
style={{
flexDirection: "row",
alignItems: "center",
alignSelf: "flex-start",
flexShrink: 0,
marginTop: compact ? 2 : 0,
marginRight: 2,
}}
>
{hasAgents ? (
<Pressable
accessibilityRole="button"
accessibilityLabel={
showAgents
? `${agentsCollapsed ? "Expand" : "Collapse"} agents for ${title}`
: `${agentRefs.length} agents`
}
onPress={() => {
if (showAgents) {
setAgentsCollapsed((prev) => !prev);
} else {
onOpenWorkspace(workspace.ref);
}
}}
style={({ pressed }) => ({
flexDirection: "row",
alignItems: "center",
gap: 3,
paddingHorizontal: 5,
paddingVertical: 6,
borderRadius: 6,
backgroundColor: pressed ? theme.colors.surface1 : "transparent",
})}
>
<Icon name="Bot" size={12} color={theme.colors.foregroundMuted} />
<Text
style={{ fontSize: 11, color: theme.colors.foregroundMuted }}
>
{agentRefs.length}
</Text>
{showAgents ? (
<Icon
name={agentsCollapsed ? "ChevronRight" : "ChevronDown"}
size={12}
color={theme.colors.foregroundMuted}
/>
) : null}
</Pressable>
) : null}
<RowIconButton
icon="Pencil"
accessibilityLabel={`Rename ${title}`}
theme={theme}
size={13}
disabled={busy}
onPress={() => setRenameOpen(true)}
/>
<RowIconButton
icon="Archive"
accessibilityLabel={`Archive ${title}`}
theme={theme}
size={13}
disabled={busy}
onPress={() => setArchiveOpen(true)}
/>
<RowIconButton
icon="MoreHorizontal"
accessibilityLabel={`Workspace actions for ${title}`}
theme={theme}
size={14}
active={actionsOpen}
onPress={() => onToggleMenu(menuKey)}
/>
</View>
</View>
{actionsOpen ? (
<View
style={{
flexDirection: "row",
flexWrap: "wrap",
gap: 6,
paddingLeft: 26,
paddingRight: 8,
paddingVertical: 4,
}}
>
<ActionPill
icon="Pencil"
label="Rename"
theme={theme}
disabled={busy}
onPress={() => setRenameOpen(true)}
/>
<ActionPill
icon={workspace.pinnedAt ? "PinOff" : "Pin"}
label={workspace.pinnedAt ? "Unpin" : "Pin"}
theme={theme}
disabled={busy}
onPress={handleTogglePin}
/>
<ActionPill
icon="Copy"
label="Copy path"
theme={theme}
disabled={busy}
onPress={handleCopyDirectory}
/>
<ActionPill
icon="Archive"
label="Archive"
theme={theme}
tone="danger"
disabled={busy}
onPress={() => setArchiveOpen(true)}
/>
</View>
) : null}
{agentsExpanded ? (
<View style={{ gap: 1 }}>
{agentRefs.map((agentRef) => (
<AgentRow
key={agentRef.key}
agentRef={agentRef}
theme={theme}
platform={platform}
isActive={activeAgentKey === agentRef.key}
actionsOpen={activeMenuKey === `agent:${agentRef.key}`}
onToggleActions={onToggleMenu}
onCloseActions={onCloseMenu}
onOpenContextMenu={onOpenContextMenu}
onOpenAgent={onOpenAgent}
/>
))}
</View>
) : null}
<RenameWorkspaceModal
open={renameOpen}
initialTitle={title}
hasCustomTitle={workspace.title !== null}
theme={theme}
saving={busy}
onClose={() => setRenameOpen(false)}
onSave={handleRename}
/>
<ConfirmArchiveModal
open={archiveOpen}
title="Archive workspace"
description={`Archive "${title}"? Active agents in this workspace will be stopped and the workspace will be hidden from the sidebar.`}
theme={theme}
archiving={busy}
onClose={() => setArchiveOpen(false)}
onConfirm={handleArchiveWorkspace}
/>
</View>
);
}