Initial commit: group-by-host Paseo sidebar plugin
This commit is contained in:
commit
dcfe97a2e6
13 files changed
+6789
No files matched your search
@@ -0,0 +1 @@
|
|||||||
|
node_modules/
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
Group workspaces, agents, and projects by their connected Paseo host in the sidebar.
|
||||||
|
|
||||||
|
Each configured host appears as a collapsible section showing its connection status and workspace count. Inside each host section, workspaces are listed with their status indicator, project name, branch, diff summary, and active or recent agents so you can jump straight to a workspace or an individual agent.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
After enabling the plugin, select **Group by host** under **Settings -> Appearance -> Sidebar view**.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Groups workspaces across all connected and configured Paseo hosts (`local` and remote hosts).
|
||||||
|
- Displays host connection status (`online`, `connecting`, `offline`, or `error`) and lets you collapse or expand individual host sections.
|
||||||
|
- Shows pinned workspaces first, sorted by recent activity, along with non-background agents nested under each workspace.
|
||||||
|
- Includes a filter bar to search by host, workspace, project, or branch, plus an **Active** filter to focus on running or attention-requiring workspaces.
|
||||||
|
- Includes a per-host project launcher (`+`) to start a new workspace on a specific host.
|
||||||
|
|
||||||
|
## Permissions and limits
|
||||||
|
|
||||||
|
This plugin runs only on the Paseo client and reads the client's synced host, workspace, agent, and project snapshots. It does not run a daemon-side service or send data externally.
|
||||||
@@ -0,0 +1,394 @@
|
|||||||
|
import type { PluginTheme } from "@getpaseo/plugin";
|
||||||
|
import { Icon, Modal } from "@getpaseo/plugin/client/ui";
|
||||||
|
import { type RefObject, useEffect, useRef, useState } from "react";
|
||||||
|
import { Pressable, Text, View } from "react-native";
|
||||||
|
|
||||||
|
export interface ContextMenuItem {
|
||||||
|
readonly id: string;
|
||||||
|
readonly label: string;
|
||||||
|
readonly icon: string;
|
||||||
|
readonly tone?: "default" | "danger";
|
||||||
|
readonly disabled?: boolean;
|
||||||
|
readonly separatorBefore?: boolean;
|
||||||
|
onSelect(): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ContextMenuRequest {
|
||||||
|
readonly clientX: number;
|
||||||
|
readonly clientY: number;
|
||||||
|
readonly title?: string;
|
||||||
|
readonly items: readonly ContextMenuItem[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DomRectLike {
|
||||||
|
left: number;
|
||||||
|
top: number;
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DomEventLike {
|
||||||
|
preventDefault(): void;
|
||||||
|
stopPropagation(): void;
|
||||||
|
clientX: number;
|
||||||
|
clientY: number;
|
||||||
|
target?: unknown;
|
||||||
|
key?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DomNodeLike {
|
||||||
|
addEventListener?(
|
||||||
|
type: string,
|
||||||
|
listener: (event: DomEventLike) => void,
|
||||||
|
capture?: boolean,
|
||||||
|
): void;
|
||||||
|
removeEventListener?(
|
||||||
|
type: string,
|
||||||
|
listener: (event: DomEventLike) => void,
|
||||||
|
capture?: boolean,
|
||||||
|
): void;
|
||||||
|
getBoundingClientRect?(): DomRectLike;
|
||||||
|
contains?(target: unknown): boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
function asDomNode(value: unknown): DomNodeLike | null {
|
||||||
|
if (!value || typeof value !== "object") return null;
|
||||||
|
return value as DomNodeLike;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDocumentNode(): DomNodeLike | null {
|
||||||
|
const globalObj = globalThis as { document?: unknown };
|
||||||
|
return asDomNode(globalObj.document);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useContextMenuTarget(
|
||||||
|
onOpen: (clientX: number, clientY: number) => void,
|
||||||
|
) {
|
||||||
|
const [target, setTarget] = useState<unknown>(null);
|
||||||
|
const onOpenRef = useRef(onOpen);
|
||||||
|
onOpenRef.current = onOpen;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const node = asDomNode(target);
|
||||||
|
if (!node || typeof node.addEventListener !== "function") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleContextMenu = (event: DomEventLike) => {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
onOpenRef.current(event.clientX, event.clientY);
|
||||||
|
};
|
||||||
|
|
||||||
|
node.addEventListener("contextmenu", handleContextMenu);
|
||||||
|
return () => {
|
||||||
|
node.removeEventListener?.("contextmenu", handleContextMenu);
|
||||||
|
};
|
||||||
|
}, [target]);
|
||||||
|
|
||||||
|
return setTarget;
|
||||||
|
}
|
||||||
|
|
||||||
|
function clamp(value: number, min: number, max: number): number {
|
||||||
|
if (max < min) return min;
|
||||||
|
return Math.min(Math.max(value, min), max);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MenuItemListProps {
|
||||||
|
items: readonly ContextMenuItem[];
|
||||||
|
theme: PluginTheme;
|
||||||
|
compact: boolean;
|
||||||
|
onSelectItem(item: ContextMenuItem): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
function MenuItemList({
|
||||||
|
items,
|
||||||
|
theme,
|
||||||
|
compact,
|
||||||
|
onSelectItem,
|
||||||
|
}: MenuItemListProps) {
|
||||||
|
const [hoveredId, setHoveredId] = useState<string | null>(null);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
{items.map((item) => {
|
||||||
|
const isDanger = item.tone === "danger";
|
||||||
|
const isHovered = hoveredId === item.id;
|
||||||
|
const foreground = isDanger
|
||||||
|
? theme.colors.statusDanger
|
||||||
|
: theme.colors.foreground;
|
||||||
|
const iconColor = isDanger
|
||||||
|
? theme.colors.statusDanger
|
||||||
|
: theme.colors.foregroundMuted;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View key={item.id}>
|
||||||
|
{item.separatorBefore ? (
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
height: 1,
|
||||||
|
marginVertical: 4,
|
||||||
|
marginHorizontal: 6,
|
||||||
|
backgroundColor: theme.colors.border,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
<Pressable
|
||||||
|
accessibilityRole="menuitem"
|
||||||
|
accessibilityLabel={item.label}
|
||||||
|
disabled={item.disabled}
|
||||||
|
onHoverIn={() => setHoveredId(item.id)}
|
||||||
|
onHoverOut={() =>
|
||||||
|
setHoveredId((prev) => (prev === item.id ? null : prev))
|
||||||
|
}
|
||||||
|
onPress={() => onSelectItem(item)}
|
||||||
|
style={({ pressed }) => ({
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: compact ? 8 : 10,
|
||||||
|
marginHorizontal: 4,
|
||||||
|
paddingHorizontal: compact ? 8 : 10,
|
||||||
|
paddingVertical: compact ? 6 : 9,
|
||||||
|
borderRadius: 6,
|
||||||
|
backgroundColor:
|
||||||
|
pressed || isHovered ? theme.colors.surface2 : "transparent",
|
||||||
|
opacity: item.disabled ? 0.5 : 1,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
name={item.icon}
|
||||||
|
size={compact ? 13 : 15}
|
||||||
|
color={iconColor}
|
||||||
|
/>
|
||||||
|
<Text
|
||||||
|
numberOfLines={1}
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
fontSize: compact ? 12 : 14,
|
||||||
|
fontWeight: "500",
|
||||||
|
color: foreground,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{item.label}
|
||||||
|
</Text>
|
||||||
|
</Pressable>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ContextMenuOverlayProps {
|
||||||
|
request: ContextMenuRequest | null;
|
||||||
|
containerRef: RefObject<unknown>;
|
||||||
|
platform: "ios" | "android" | "web";
|
||||||
|
theme: PluginTheme;
|
||||||
|
onClose(): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ContextMenuOverlay({
|
||||||
|
request,
|
||||||
|
containerRef,
|
||||||
|
platform,
|
||||||
|
theme,
|
||||||
|
onClose,
|
||||||
|
}: ContextMenuOverlayProps) {
|
||||||
|
const backdropRef = useRef<unknown>(null);
|
||||||
|
const menuRef = useRef<unknown>(null);
|
||||||
|
const [menuSize, setMenuSize] = useState<{
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
|
} | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setMenuSize(null);
|
||||||
|
}, [request]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!request || platform !== "web") return;
|
||||||
|
const doc = getDocumentNode();
|
||||||
|
if (!doc || typeof doc.addEventListener !== "function") return;
|
||||||
|
|
||||||
|
const handleKeyDown = (event: DomEventLike) => {
|
||||||
|
if (event.key === "Escape") {
|
||||||
|
event.preventDefault();
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handlePointerDown = (event: DomEventLike) => {
|
||||||
|
const menuNode = asDomNode(menuRef.current);
|
||||||
|
if (menuNode?.contains?.(event.target)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const containerNode = asDomNode(containerRef.current);
|
||||||
|
if (!containerNode?.contains?.(event.target)) {
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
doc.addEventListener("keydown", handleKeyDown, true);
|
||||||
|
doc.addEventListener("pointerdown", handlePointerDown, true);
|
||||||
|
return () => {
|
||||||
|
doc.removeEventListener?.("keydown", handleKeyDown, true);
|
||||||
|
doc.removeEventListener?.("pointerdown", handlePointerDown, true);
|
||||||
|
};
|
||||||
|
}, [containerRef, onClose, platform, request]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!request || platform !== "web") return;
|
||||||
|
const backdropNode = asDomNode(backdropRef.current);
|
||||||
|
if (!backdropNode || typeof backdropNode.addEventListener !== "function") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleContextMenu = (event: DomEventLike) => {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
onClose();
|
||||||
|
};
|
||||||
|
|
||||||
|
backdropNode.addEventListener("contextmenu", handleContextMenu);
|
||||||
|
return () => {
|
||||||
|
backdropNode.removeEventListener?.("contextmenu", handleContextMenu);
|
||||||
|
};
|
||||||
|
}, [onClose, platform, request]);
|
||||||
|
|
||||||
|
if (!request) return null;
|
||||||
|
|
||||||
|
function handleSelectItem(item: ContextMenuItem) {
|
||||||
|
onClose();
|
||||||
|
item.onSelect();
|
||||||
|
}
|
||||||
|
|
||||||
|
const containerRect =
|
||||||
|
platform === "web"
|
||||||
|
? asDomNode(containerRef.current)?.getBoundingClientRect?.() ?? null
|
||||||
|
: null;
|
||||||
|
|
||||||
|
if (!containerRect) {
|
||||||
|
return (
|
||||||
|
<Modal
|
||||||
|
title={request.title ?? "Actions"}
|
||||||
|
open
|
||||||
|
onOpenChange={(nextOpen) => {
|
||||||
|
if (!nextOpen) onClose();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Modal.Content>
|
||||||
|
<MenuItemList
|
||||||
|
items={request.items}
|
||||||
|
theme={theme}
|
||||||
|
compact={false}
|
||||||
|
onSelectItem={handleSelectItem}
|
||||||
|
/>
|
||||||
|
</Modal.Content>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const padding = 8;
|
||||||
|
const estimatedWidth = menuSize?.width ?? 192;
|
||||||
|
const estimatedHeight = menuSize?.height ?? request.items.length * 32 + 36;
|
||||||
|
const rawLeft = request.clientX - containerRect.left;
|
||||||
|
const rawTop = request.clientY - containerRect.top;
|
||||||
|
const left = clamp(
|
||||||
|
rawLeft,
|
||||||
|
padding,
|
||||||
|
containerRect.width - estimatedWidth - padding,
|
||||||
|
);
|
||||||
|
const top = clamp(
|
||||||
|
rawTop,
|
||||||
|
padding,
|
||||||
|
containerRect.height - estimatedHeight - padding,
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
pointerEvents="box-none"
|
||||||
|
style={{
|
||||||
|
position: "absolute",
|
||||||
|
top: 0,
|
||||||
|
right: 0,
|
||||||
|
bottom: 0,
|
||||||
|
left: 0,
|
||||||
|
zIndex: 50,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Pressable
|
||||||
|
ref={backdropRef as never}
|
||||||
|
accessibilityLabel="Dismiss context menu"
|
||||||
|
onPress={onClose}
|
||||||
|
style={{
|
||||||
|
position: "absolute",
|
||||||
|
top: 0,
|
||||||
|
right: 0,
|
||||||
|
bottom: 0,
|
||||||
|
left: 0,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<View
|
||||||
|
ref={menuRef as never}
|
||||||
|
accessibilityRole="menu"
|
||||||
|
onLayout={(event) => {
|
||||||
|
const { width, height } = event.nativeEvent.layout;
|
||||||
|
setMenuSize((prev) =>
|
||||||
|
prev && prev.width === width && prev.height === height
|
||||||
|
? prev
|
||||||
|
: { width, height },
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
style={{
|
||||||
|
position: "absolute",
|
||||||
|
left,
|
||||||
|
top,
|
||||||
|
minWidth: 184,
|
||||||
|
maxWidth: Math.max(184, containerRect.width - padding * 2),
|
||||||
|
paddingVertical: 4,
|
||||||
|
borderRadius: 10,
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: theme.colors.border,
|
||||||
|
backgroundColor: theme.colors.surface1,
|
||||||
|
shadowColor: "#000000",
|
||||||
|
shadowOpacity: 0.24,
|
||||||
|
shadowRadius: 12,
|
||||||
|
shadowOffset: { width: 0, height: 6 },
|
||||||
|
elevation: 8,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{request.title ? (
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
paddingHorizontal: 12,
|
||||||
|
paddingTop: 4,
|
||||||
|
paddingBottom: 6,
|
||||||
|
marginBottom: 4,
|
||||||
|
borderBottomWidth: 1,
|
||||||
|
borderBottomColor: theme.colors.border,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Text
|
||||||
|
numberOfLines={1}
|
||||||
|
style={{
|
||||||
|
fontSize: 11,
|
||||||
|
fontWeight: "600",
|
||||||
|
color: theme.colors.foregroundMuted,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{request.title}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<MenuItemList
|
||||||
|
items={request.items}
|
||||||
|
theme={theme}
|
||||||
|
compact
|
||||||
|
onSelectItem={handleSelectItem}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,156 @@
|
|||||||
|
import type {
|
||||||
|
PluginAgentSnapshot,
|
||||||
|
PluginTheme,
|
||||||
|
PluginWorkspaceSnapshot,
|
||||||
|
WorkspaceIndicator,
|
||||||
|
} from "@getpaseo/plugin";
|
||||||
|
import type { PluginHostSummary } from "@getpaseo/plugin/client";
|
||||||
|
|
||||||
|
export function isWorkspaceActive(workspace: PluginWorkspaceSnapshot): boolean {
|
||||||
|
return (
|
||||||
|
workspace.indicator === "running" ||
|
||||||
|
workspace.indicator === "needs_input" ||
|
||||||
|
workspace.indicator === "attention" ||
|
||||||
|
workspace.indicator === "failed"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function compareWorkspaces(
|
||||||
|
left: PluginWorkspaceSnapshot,
|
||||||
|
right: PluginWorkspaceSnapshot,
|
||||||
|
): number {
|
||||||
|
const leftPinned = left.pinnedAt !== null;
|
||||||
|
const rightPinned = right.pinnedAt !== null;
|
||||||
|
if (leftPinned !== rightPinned) {
|
||||||
|
return leftPinned ? -1 : 1;
|
||||||
|
}
|
||||||
|
if (leftPinned && rightPinned && left.pinnedAt !== right.pinnedAt) {
|
||||||
|
return (right.pinnedAt ?? "").localeCompare(left.pinnedAt ?? "");
|
||||||
|
}
|
||||||
|
|
||||||
|
const leftTime = left.lastPromptAt ?? left.createdAt ?? "";
|
||||||
|
const rightTime = right.lastPromptAt ?? right.createdAt ?? "";
|
||||||
|
if (leftTime !== rightTime) {
|
||||||
|
return rightTime.localeCompare(leftTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
const leftLabel = left.title ?? left.name;
|
||||||
|
const rightLabel = right.title ?? right.name;
|
||||||
|
return leftLabel.localeCompare(rightLabel);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function compareAgents(
|
||||||
|
left: PluginAgentSnapshot,
|
||||||
|
right: PluginAgentSnapshot,
|
||||||
|
): number {
|
||||||
|
const leftPriority = agentPriority(left);
|
||||||
|
const rightPriority = agentPriority(right);
|
||||||
|
if (leftPriority !== rightPriority) {
|
||||||
|
return leftPriority - rightPriority;
|
||||||
|
}
|
||||||
|
if (left.lastActivityAt !== right.lastActivityAt) {
|
||||||
|
return right.lastActivityAt.localeCompare(left.lastActivityAt);
|
||||||
|
}
|
||||||
|
return left.createdAt.localeCompare(right.createdAt);
|
||||||
|
}
|
||||||
|
|
||||||
|
function agentPriority(agent: PluginAgentSnapshot): number {
|
||||||
|
if (agent.requiresAttention) return 0;
|
||||||
|
if (agent.status === "running" || agent.status === "initializing") return 1;
|
||||||
|
if (agent.status === "error") return 2;
|
||||||
|
if (agent.status === "idle") return 3;
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getHostStatusColor(
|
||||||
|
status: PluginHostSummary["status"],
|
||||||
|
theme: PluginTheme,
|
||||||
|
): string {
|
||||||
|
switch (status) {
|
||||||
|
case "online":
|
||||||
|
return theme.colors.statusSuccess;
|
||||||
|
case "connecting":
|
||||||
|
return theme.colors.statusWarning;
|
||||||
|
case "error":
|
||||||
|
return theme.colors.statusDanger;
|
||||||
|
case "offline":
|
||||||
|
case "idle":
|
||||||
|
return theme.colors.foregroundMuted;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getHostStatusLabel(
|
||||||
|
status: PluginHostSummary["status"],
|
||||||
|
): string | null {
|
||||||
|
switch (status) {
|
||||||
|
case "online":
|
||||||
|
return null;
|
||||||
|
case "connecting":
|
||||||
|
return "Connecting";
|
||||||
|
case "offline":
|
||||||
|
return "Offline";
|
||||||
|
case "error":
|
||||||
|
return "Error";
|
||||||
|
case "idle":
|
||||||
|
return "Idle";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getWorkspaceIndicatorColor(
|
||||||
|
indicator: WorkspaceIndicator,
|
||||||
|
theme: PluginTheme,
|
||||||
|
): string | null {
|
||||||
|
switch (indicator) {
|
||||||
|
case "needs_input":
|
||||||
|
return theme.colors.statusWarning;
|
||||||
|
case "failed":
|
||||||
|
return theme.colors.statusDanger;
|
||||||
|
case "running":
|
||||||
|
return theme.colors.statusSuccess;
|
||||||
|
case "attention":
|
||||||
|
return theme.colors.accent;
|
||||||
|
case "done":
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getAgentStatusColor(
|
||||||
|
agent: PluginAgentSnapshot,
|
||||||
|
theme: PluginTheme,
|
||||||
|
): string {
|
||||||
|
if (agent.requiresAttention) {
|
||||||
|
return agent.attentionReason === "error"
|
||||||
|
? theme.colors.statusDanger
|
||||||
|
: theme.colors.statusWarning;
|
||||||
|
}
|
||||||
|
switch (agent.status) {
|
||||||
|
case "running":
|
||||||
|
case "initializing":
|
||||||
|
return theme.colors.statusSuccess;
|
||||||
|
case "error":
|
||||||
|
return theme.colors.statusDanger;
|
||||||
|
case "idle":
|
||||||
|
case "closed":
|
||||||
|
return theme.colors.foregroundMuted;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getAgentSubtitle(agent: PluginAgentSnapshot): string {
|
||||||
|
if (agent.requiresAttention && agent.attentionReason) {
|
||||||
|
switch (agent.attentionReason) {
|
||||||
|
case "permission":
|
||||||
|
return "Needs permission";
|
||||||
|
case "error":
|
||||||
|
return "Error";
|
||||||
|
case "finished":
|
||||||
|
return "Finished";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (agent.status === "running") {
|
||||||
|
return agent.model ? `${agent.provider} · ${agent.model}` : `${agent.provider} · Running`;
|
||||||
|
}
|
||||||
|
if (agent.status === "initializing") {
|
||||||
|
return "Starting";
|
||||||
|
}
|
||||||
|
return agent.model ?? agent.provider;
|
||||||
|
}
|
||||||
@@ -0,0 +1,342 @@
|
|||||||
|
import type { PluginTheme } from "@getpaseo/plugin";
|
||||||
|
import type {
|
||||||
|
AgentRef,
|
||||||
|
PluginHostSummary,
|
||||||
|
ProjectRef,
|
||||||
|
WorkspaceRef,
|
||||||
|
} from "@getpaseo/plugin/client";
|
||||||
|
import { useProject } from "@getpaseo/plugin/client";
|
||||||
|
import { Icon } from "@getpaseo/plugin/client/ui";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { Pressable, Text, View } from "react-native";
|
||||||
|
import type { ContextMenuRequest } from "./context-menu";
|
||||||
|
import { getHostStatusColor, getHostStatusLabel } from "./grouping";
|
||||||
|
import { WorkspaceRow } from "./workspace-row";
|
||||||
|
|
||||||
|
interface ProjectItemProps {
|
||||||
|
projectRef: ProjectRef;
|
||||||
|
theme: PluginTheme;
|
||||||
|
onOpenProject(ref: ProjectRef): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ProjectItem({ projectRef, theme, onOpenProject }: ProjectItemProps) {
|
||||||
|
const project = useProject(projectRef);
|
||||||
|
if (!project) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Pressable
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel={`New workspace in ${project.displayName}`}
|
||||||
|
onPress={() => onOpenProject(project.ref)}
|
||||||
|
style={({ pressed }) => ({
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: 7,
|
||||||
|
paddingVertical: 5,
|
||||||
|
paddingHorizontal: 8,
|
||||||
|
borderRadius: 6,
|
||||||
|
backgroundColor: pressed ? theme.colors.surface2 : "transparent",
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
name={project.kind === "git" ? "FolderGit2" : "Folder"}
|
||||||
|
size={13}
|
||||||
|
color={theme.colors.accent}
|
||||||
|
/>
|
||||||
|
<Text
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
minWidth: 0,
|
||||||
|
fontSize: 12,
|
||||||
|
color: theme.colors.foreground,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{project.displayName}
|
||||||
|
</Text>
|
||||||
|
<Icon name="Plus" size={12} color={theme.colors.foregroundMuted} />
|
||||||
|
</Pressable>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface HostGroupProps {
|
||||||
|
hostId: string;
|
||||||
|
hostLabel: string;
|
||||||
|
hostStatus: PluginHostSummary["status"];
|
||||||
|
workspaceRefs: readonly WorkspaceRef[];
|
||||||
|
projectRefs: readonly ProjectRef[];
|
||||||
|
agentsByWorkspace: ReadonlyMap<string, readonly AgentRef[]>;
|
||||||
|
collapsed: boolean;
|
||||||
|
onToggleCollapsed(hostId: string): void;
|
||||||
|
theme: PluginTheme;
|
||||||
|
compact: boolean;
|
||||||
|
platform: "ios" | "android" | "web";
|
||||||
|
showAgents: boolean;
|
||||||
|
activeWorkspaceKey: string | null;
|
||||||
|
activeAgentKey: string | null;
|
||||||
|
activeMenuKey: string | null;
|
||||||
|
hasActiveWorkspaceInHost: boolean;
|
||||||
|
onToggleMenu(key: string): void;
|
||||||
|
onCloseMenu(): void;
|
||||||
|
onOpenContextMenu(request: ContextMenuRequest): void;
|
||||||
|
onOpenWorkspace(ref: WorkspaceRef): void;
|
||||||
|
onOpenAgent(ref: AgentRef): void;
|
||||||
|
onOpenProject(ref: ProjectRef): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function HostGroup({
|
||||||
|
hostId,
|
||||||
|
hostLabel,
|
||||||
|
hostStatus,
|
||||||
|
workspaceRefs,
|
||||||
|
projectRefs,
|
||||||
|
agentsByWorkspace,
|
||||||
|
collapsed,
|
||||||
|
onToggleCollapsed,
|
||||||
|
theme,
|
||||||
|
compact,
|
||||||
|
platform,
|
||||||
|
showAgents,
|
||||||
|
activeWorkspaceKey,
|
||||||
|
activeAgentKey,
|
||||||
|
activeMenuKey,
|
||||||
|
hasActiveWorkspaceInHost,
|
||||||
|
onToggleMenu,
|
||||||
|
onCloseMenu,
|
||||||
|
onOpenContextMenu,
|
||||||
|
onOpenWorkspace,
|
||||||
|
onOpenAgent,
|
||||||
|
onOpenProject,
|
||||||
|
}: HostGroupProps) {
|
||||||
|
const [projectsOpen, setProjectsOpen] = useState(false);
|
||||||
|
|
||||||
|
const statusColor = getHostStatusColor(hostStatus, theme);
|
||||||
|
const statusLabel = getHostStatusLabel(hostStatus);
|
||||||
|
const hasProjects = projectRefs.length > 0;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
borderRadius: 10,
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: hasActiveWorkspaceInHost
|
||||||
|
? theme.colors.accent
|
||||||
|
: theme.colors.border,
|
||||||
|
backgroundColor: theme.colors.surface1,
|
||||||
|
overflow: "hidden",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
paddingRight: 6,
|
||||||
|
backgroundColor: theme.colors.surface1,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Pressable
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel={`${collapsed ? "Expand" : "Collapse"} host ${hostLabel}`}
|
||||||
|
onPress={() => onToggleCollapsed(hostId)}
|
||||||
|
style={({ pressed }) => ({
|
||||||
|
flex: 1,
|
||||||
|
minWidth: 0,
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: 8,
|
||||||
|
paddingVertical: compact ? 9 : 7,
|
||||||
|
paddingLeft: 10,
|
||||||
|
paddingRight: 6,
|
||||||
|
backgroundColor: pressed ? theme.colors.surface2 : "transparent",
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
name={collapsed ? "ChevronRight" : "ChevronDown"}
|
||||||
|
size={14}
|
||||||
|
color={theme.colors.foregroundMuted}
|
||||||
|
/>
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
width: 8,
|
||||||
|
height: 8,
|
||||||
|
borderRadius: 4,
|
||||||
|
flexShrink: 0,
|
||||||
|
backgroundColor: statusColor,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Icon name="Server" size={13} color={theme.colors.foregroundMuted} />
|
||||||
|
<Text
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
minWidth: 0,
|
||||||
|
fontSize: 13,
|
||||||
|
fontWeight: "600",
|
||||||
|
color: theme.colors.foreground,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{hostLabel}
|
||||||
|
</Text>
|
||||||
|
{statusLabel ? (
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
paddingHorizontal: 6,
|
||||||
|
paddingVertical: 2,
|
||||||
|
borderRadius: 999,
|
||||||
|
backgroundColor: theme.colors.surface2,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Text
|
||||||
|
style={{
|
||||||
|
fontSize: 10,
|
||||||
|
fontWeight: "600",
|
||||||
|
color: statusColor,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{statusLabel}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
minWidth: 20,
|
||||||
|
paddingHorizontal: 6,
|
||||||
|
paddingVertical: 2,
|
||||||
|
borderRadius: 999,
|
||||||
|
alignItems: "center",
|
||||||
|
backgroundColor: theme.colors.surface2,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Text
|
||||||
|
style={{
|
||||||
|
fontSize: 11,
|
||||||
|
fontWeight: "600",
|
||||||
|
color: theme.colors.foregroundMuted,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{workspaceRefs.length}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
</Pressable>
|
||||||
|
|
||||||
|
{hasProjects ? (
|
||||||
|
<Pressable
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel={`New workspace on ${hostLabel}`}
|
||||||
|
onPress={() => {
|
||||||
|
if (collapsed) {
|
||||||
|
onToggleCollapsed(hostId);
|
||||||
|
setProjectsOpen(true);
|
||||||
|
} else {
|
||||||
|
setProjectsOpen((prev) => !prev);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
style={({ pressed }) => ({
|
||||||
|
padding: 6,
|
||||||
|
borderRadius: 6,
|
||||||
|
backgroundColor:
|
||||||
|
projectsOpen || pressed ? theme.colors.surface2 : "transparent",
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
name={projectsOpen ? "X" : "Plus"}
|
||||||
|
size={14}
|
||||||
|
color={
|
||||||
|
projectsOpen
|
||||||
|
? theme.colors.foreground
|
||||||
|
: theme.colors.foregroundMuted
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</Pressable>
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
|
||||||
|
{!collapsed ? (
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
paddingHorizontal: 6,
|
||||||
|
paddingBottom: 6,
|
||||||
|
paddingTop: 2,
|
||||||
|
gap: 4,
|
||||||
|
borderTopWidth: 1,
|
||||||
|
borderTopColor: theme.colors.border,
|
||||||
|
backgroundColor: theme.colors.surface0,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{projectsOpen && hasProjects ? (
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
padding: 6,
|
||||||
|
marginTop: 4,
|
||||||
|
borderRadius: 8,
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: theme.colors.border,
|
||||||
|
backgroundColor: theme.colors.surface1,
|
||||||
|
gap: 2,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Text
|
||||||
|
style={{
|
||||||
|
fontSize: 10,
|
||||||
|
fontWeight: "600",
|
||||||
|
textTransform: "uppercase",
|
||||||
|
color: theme.colors.foregroundMuted,
|
||||||
|
paddingHorizontal: 8,
|
||||||
|
paddingBottom: 2,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
New workspace from project
|
||||||
|
</Text>
|
||||||
|
{projectRefs.map((projectRef) => (
|
||||||
|
<ProjectItem
|
||||||
|
key={projectRef.key}
|
||||||
|
projectRef={projectRef}
|
||||||
|
theme={theme}
|
||||||
|
onOpenProject={(ref) => {
|
||||||
|
setProjectsOpen(false);
|
||||||
|
onOpenProject(ref);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{workspaceRefs.length > 0 ? (
|
||||||
|
<View style={{ gap: 2, paddingTop: 2 }}>
|
||||||
|
{workspaceRefs.map((workspaceRef) => (
|
||||||
|
<WorkspaceRow
|
||||||
|
key={workspaceRef.key}
|
||||||
|
workspaceRef={workspaceRef}
|
||||||
|
agentRefs={agentsByWorkspace.get(workspaceRef.key) ?? []}
|
||||||
|
theme={theme}
|
||||||
|
compact={compact}
|
||||||
|
platform={platform}
|
||||||
|
showAgents={showAgents}
|
||||||
|
activeWorkspaceKey={activeWorkspaceKey}
|
||||||
|
activeAgentKey={activeAgentKey}
|
||||||
|
activeMenuKey={activeMenuKey}
|
||||||
|
onToggleMenu={onToggleMenu}
|
||||||
|
onCloseMenu={onCloseMenu}
|
||||||
|
onOpenContextMenu={onOpenContextMenu}
|
||||||
|
onOpenWorkspace={onOpenWorkspace}
|
||||||
|
onOpenAgent={onOpenAgent}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
) : (
|
||||||
|
<Text
|
||||||
|
style={{
|
||||||
|
paddingVertical: 10,
|
||||||
|
paddingHorizontal: 10,
|
||||||
|
fontSize: 12,
|
||||||
|
color: theme.colors.foregroundMuted,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{hostStatus === "offline" || hostStatus === "error"
|
||||||
|
? "Host unavailable."
|
||||||
|
: "No workspaces on this host."}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,508 @@
|
|||||||
|
import type {
|
||||||
|
PluginProjectSnapshot,
|
||||||
|
PluginWorkspaceSnapshot,
|
||||||
|
} from "@getpaseo/plugin";
|
||||||
|
import type {
|
||||||
|
AgentRef,
|
||||||
|
PluginHostSummary,
|
||||||
|
PluginSidebarViewProps,
|
||||||
|
ProjectRef,
|
||||||
|
WorkspaceRef,
|
||||||
|
} from "@getpaseo/plugin/client";
|
||||||
|
import {
|
||||||
|
useAgents,
|
||||||
|
useHosts,
|
||||||
|
useProjects,
|
||||||
|
useWorkspaces,
|
||||||
|
} from "@getpaseo/plugin/client";
|
||||||
|
import { Icon, ScrollView, TextInput } from "@getpaseo/plugin/client/ui";
|
||||||
|
import { useCallback, useMemo, useRef, useState } from "react";
|
||||||
|
import { Pressable, Text, View } from "react-native";
|
||||||
|
import {
|
||||||
|
ContextMenuOverlay,
|
||||||
|
type ContextMenuRequest,
|
||||||
|
} from "./context-menu";
|
||||||
|
import {
|
||||||
|
compareAgents,
|
||||||
|
compareWorkspaces,
|
||||||
|
isWorkspaceActive,
|
||||||
|
} from "./grouping";
|
||||||
|
import { HostGroup } from "./host-group";
|
||||||
|
|
||||||
|
interface HostEntry {
|
||||||
|
readonly hostId: string;
|
||||||
|
readonly label: string;
|
||||||
|
readonly status: PluginHostSummary["status"];
|
||||||
|
readonly workspaceRefs: readonly WorkspaceRef[];
|
||||||
|
readonly projectRefs: readonly ProjectRef[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function HostGroupedSidebarView({
|
||||||
|
theme,
|
||||||
|
layout,
|
||||||
|
active,
|
||||||
|
navigation,
|
||||||
|
}: PluginSidebarViewProps) {
|
||||||
|
const rootRef = useRef<unknown>(null);
|
||||||
|
const hosts = useHosts();
|
||||||
|
const [searchText, setSearchText] = useState("");
|
||||||
|
const [activeOnly, setActiveOnly] = useState(false);
|
||||||
|
const [showAgents, setShowAgents] = useState(true);
|
||||||
|
const [collapsedHostIds, setCollapsedHostIds] = useState<ReadonlySet<string>>(
|
||||||
|
() => new Set(),
|
||||||
|
);
|
||||||
|
const [activeMenuKey, setActiveMenuKey] = useState<string | null>(null);
|
||||||
|
const [contextMenu, setContextMenu] = useState<ContextMenuRequest | null>(
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
|
||||||
|
const toggleMenu = useCallback((key: string) => {
|
||||||
|
setContextMenu(null);
|
||||||
|
setActiveMenuKey((previous) => (previous === key ? null : key));
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const closeMenu = useCallback(() => {
|
||||||
|
setActiveMenuKey(null);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const openContextMenu = useCallback((request: ContextMenuRequest) => {
|
||||||
|
setActiveMenuKey(null);
|
||||||
|
setContextMenu(request);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const closeContextMenu = useCallback(() => {
|
||||||
|
setContextMenu(null);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const normalizedQuery = searchText.trim().toLowerCase();
|
||||||
|
|
||||||
|
const matchingHostIds = useMemo(() => {
|
||||||
|
if (!normalizedQuery) return null;
|
||||||
|
const matched = new Set<string>();
|
||||||
|
for (const host of hosts) {
|
||||||
|
if (
|
||||||
|
host.label.toLowerCase().includes(normalizedQuery) ||
|
||||||
|
host.serverId.toLowerCase().includes(normalizedQuery)
|
||||||
|
) {
|
||||||
|
matched.add(host.serverId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return matched;
|
||||||
|
}, [hosts, normalizedQuery]);
|
||||||
|
|
||||||
|
const workspaceQuery = useMemo(
|
||||||
|
() => ({
|
||||||
|
where: (workspace: PluginWorkspaceSnapshot) => {
|
||||||
|
if (workspace.background || workspace.archivingAt !== null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (activeOnly && !isWorkspaceActive(workspace)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!normalizedQuery) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (matchingHostIds?.has(workspace.hostId)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
const fields = [
|
||||||
|
workspace.title,
|
||||||
|
workspace.name,
|
||||||
|
workspace.projectDisplayName,
|
||||||
|
workspace.branch,
|
||||||
|
];
|
||||||
|
return fields.some(
|
||||||
|
(field) =>
|
||||||
|
field !== null &&
|
||||||
|
field.toLowerCase().includes(normalizedQuery),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
orderBy: compareWorkspaces,
|
||||||
|
groupBy: (workspace: PluginWorkspaceSnapshot) => workspace.hostId,
|
||||||
|
}),
|
||||||
|
[activeOnly, matchingHostIds, normalizedQuery],
|
||||||
|
);
|
||||||
|
|
||||||
|
const agentQuery = useMemo(
|
||||||
|
() => ({
|
||||||
|
where: (agent: { readonly background: boolean }) => !agent.background,
|
||||||
|
orderBy: compareAgents,
|
||||||
|
groupBy: (agent: { readonly workspace: WorkspaceRef }) =>
|
||||||
|
agent.workspace.key,
|
||||||
|
}),
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
|
const projectQuery = useMemo(
|
||||||
|
() => ({
|
||||||
|
orderBy: (left: PluginProjectSnapshot, right: PluginProjectSnapshot) =>
|
||||||
|
left.displayName.localeCompare(right.displayName),
|
||||||
|
groupBy: (project: PluginProjectSnapshot) => project.hostId,
|
||||||
|
}),
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
|
const workspaceGroups = useWorkspaces(workspaceQuery);
|
||||||
|
const agentGroups = useAgents(agentQuery);
|
||||||
|
const projectGroups = useProjects(projectQuery);
|
||||||
|
|
||||||
|
const agentsByWorkspace = useMemo(() => {
|
||||||
|
const map = new Map<string, readonly AgentRef[]>();
|
||||||
|
for (const group of agentGroups) {
|
||||||
|
map.set(group.key, group.items);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}, [agentGroups]);
|
||||||
|
|
||||||
|
const projectsByHost = useMemo(() => {
|
||||||
|
const map = new Map<string, readonly ProjectRef[]>();
|
||||||
|
for (const group of projectGroups) {
|
||||||
|
map.set(group.key, group.items);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}, [projectGroups]);
|
||||||
|
|
||||||
|
const hostEntries = useMemo<readonly HostEntry[]>(() => {
|
||||||
|
const workspacesByHost = new Map<string, readonly WorkspaceRef[]>();
|
||||||
|
for (const group of workspaceGroups) {
|
||||||
|
workspacesByHost.set(group.key, group.items);
|
||||||
|
}
|
||||||
|
|
||||||
|
const entries: HostEntry[] = [];
|
||||||
|
const seen = new Set<string>();
|
||||||
|
|
||||||
|
for (const host of hosts) {
|
||||||
|
seen.add(host.serverId);
|
||||||
|
const hostWorkspaces = workspacesByHost.get(host.serverId) ?? [];
|
||||||
|
const hostMatchesQuery =
|
||||||
|
!normalizedQuery ||
|
||||||
|
Boolean(matchingHostIds?.has(host.serverId)) ||
|
||||||
|
hostWorkspaces.length > 0;
|
||||||
|
const matchesFilter = !activeOnly || hostWorkspaces.length > 0;
|
||||||
|
if (hostMatchesQuery && matchesFilter) {
|
||||||
|
entries.push({
|
||||||
|
hostId: host.serverId,
|
||||||
|
label: host.label || host.serverId,
|
||||||
|
status: host.status,
|
||||||
|
workspaceRefs: hostWorkspaces,
|
||||||
|
projectRefs: projectsByHost.get(host.serverId) ?? [],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const extraHostIds = [...workspacesByHost.keys()]
|
||||||
|
.filter((hostId) => !seen.has(hostId))
|
||||||
|
.sort((a, b) => a.localeCompare(b));
|
||||||
|
|
||||||
|
for (const hostId of extraHostIds) {
|
||||||
|
entries.push({
|
||||||
|
hostId,
|
||||||
|
label: hostId,
|
||||||
|
status: "online",
|
||||||
|
workspaceRefs: workspacesByHost.get(hostId) ?? [],
|
||||||
|
projectRefs: projectsByHost.get(hostId) ?? [],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
}, [
|
||||||
|
activeOnly,
|
||||||
|
hosts,
|
||||||
|
matchingHostIds,
|
||||||
|
normalizedQuery,
|
||||||
|
projectsByHost,
|
||||||
|
workspaceGroups,
|
||||||
|
]);
|
||||||
|
|
||||||
|
const allCollapsed =
|
||||||
|
hostEntries.length > 0 &&
|
||||||
|
hostEntries.every((entry) => collapsedHostIds.has(entry.hostId));
|
||||||
|
|
||||||
|
const toggleHostCollapsed = useCallback((hostId: string) => {
|
||||||
|
setCollapsedHostIds((previous) => {
|
||||||
|
const next = new Set(previous);
|
||||||
|
if (next.has(hostId)) {
|
||||||
|
next.delete(hostId);
|
||||||
|
} else {
|
||||||
|
next.add(hostId);
|
||||||
|
}
|
||||||
|
return next;
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const toggleCollapseAll = useCallback(() => {
|
||||||
|
setCollapsedHostIds((previous) => {
|
||||||
|
if (
|
||||||
|
hostEntries.length > 0 &&
|
||||||
|
hostEntries.every((entry) => previous.has(entry.hostId))
|
||||||
|
) {
|
||||||
|
return new Set();
|
||||||
|
}
|
||||||
|
return new Set(hostEntries.map((entry) => entry.hostId));
|
||||||
|
});
|
||||||
|
}, [hostEntries]);
|
||||||
|
|
||||||
|
const activeWorkspaceKey = active.workspace?.key ?? null;
|
||||||
|
const activeAgentKey = active.agent?.key ?? null;
|
||||||
|
const activeHostId = active.workspace?.hostId ?? active.agent?.hostId ?? null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
ref={rootRef as never}
|
||||||
|
style={{ flex: 1, backgroundColor: theme.colors.surface0 }}
|
||||||
|
>
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
paddingHorizontal: 10,
|
||||||
|
paddingTop: 8,
|
||||||
|
paddingBottom: 8,
|
||||||
|
gap: 8,
|
||||||
|
borderBottomWidth: 1,
|
||||||
|
borderBottomColor: theme.colors.border,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: 6,
|
||||||
|
paddingHorizontal: 8,
|
||||||
|
paddingVertical: layout.compact ? 6 : 5,
|
||||||
|
borderRadius: 8,
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: theme.colors.border,
|
||||||
|
backgroundColor: theme.colors.surface1,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Icon name="Search" size={14} color={theme.colors.foregroundMuted} />
|
||||||
|
<TextInput
|
||||||
|
value={searchText}
|
||||||
|
onChangeText={setSearchText}
|
||||||
|
placeholder="Filter hosts or workspaces..."
|
||||||
|
placeholderTextColor={theme.colors.foregroundMuted}
|
||||||
|
accessibilityLabel="Filter hosts or workspaces"
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
fontSize: 12,
|
||||||
|
paddingVertical: 0,
|
||||||
|
color: theme.colors.foreground,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{searchText.length > 0 ? (
|
||||||
|
<Pressable
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel="Clear filter"
|
||||||
|
onPress={() => setSearchText("")}
|
||||||
|
style={{ padding: 2 }}
|
||||||
|
>
|
||||||
|
<Icon name="X" size={13} color={theme.colors.foregroundMuted} />
|
||||||
|
</Pressable>
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "space-between",
|
||||||
|
gap: 6,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<View style={{ flexDirection: "row", alignItems: "center", gap: 6 }}>
|
||||||
|
<Pressable
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel="Filter active workspaces"
|
||||||
|
onPress={() => setActiveOnly((prev) => !prev)}
|
||||||
|
style={{
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: 4,
|
||||||
|
paddingHorizontal: 8,
|
||||||
|
paddingVertical: 4,
|
||||||
|
borderRadius: 999,
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: activeOnly
|
||||||
|
? theme.colors.accent
|
||||||
|
: theme.colors.border,
|
||||||
|
backgroundColor: activeOnly
|
||||||
|
? theme.colors.accent
|
||||||
|
: theme.colors.surface1,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
name="Filter"
|
||||||
|
size={11}
|
||||||
|
color={
|
||||||
|
activeOnly
|
||||||
|
? theme.colors.accentForeground
|
||||||
|
: theme.colors.foregroundMuted
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Text
|
||||||
|
style={{
|
||||||
|
fontSize: 11,
|
||||||
|
fontWeight: "600",
|
||||||
|
color: activeOnly
|
||||||
|
? theme.colors.accentForeground
|
||||||
|
: theme.colors.foreground,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Active
|
||||||
|
</Text>
|
||||||
|
</Pressable>
|
||||||
|
|
||||||
|
<Pressable
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel="Toggle agents list"
|
||||||
|
onPress={() => setShowAgents((prev) => !prev)}
|
||||||
|
style={{
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: 4,
|
||||||
|
paddingHorizontal: 8,
|
||||||
|
paddingVertical: 4,
|
||||||
|
borderRadius: 999,
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: showAgents
|
||||||
|
? theme.colors.accent
|
||||||
|
: theme.colors.border,
|
||||||
|
backgroundColor: showAgents
|
||||||
|
? theme.colors.surface2
|
||||||
|
: theme.colors.surface1,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
name="Bot"
|
||||||
|
size={11}
|
||||||
|
color={
|
||||||
|
showAgents
|
||||||
|
? theme.colors.foreground
|
||||||
|
: theme.colors.foregroundMuted
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Text
|
||||||
|
style={{
|
||||||
|
fontSize: 11,
|
||||||
|
fontWeight: "600",
|
||||||
|
color: showAgents
|
||||||
|
? theme.colors.foreground
|
||||||
|
: theme.colors.foregroundMuted,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Agents
|
||||||
|
</Text>
|
||||||
|
</Pressable>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
{hostEntries.length > 1 ? (
|
||||||
|
<Pressable
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel={
|
||||||
|
allCollapsed ? "Expand all hosts" : "Collapse all hosts"
|
||||||
|
}
|
||||||
|
onPress={toggleCollapseAll}
|
||||||
|
style={({ pressed }) => ({
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: 4,
|
||||||
|
paddingHorizontal: 6,
|
||||||
|
paddingVertical: 4,
|
||||||
|
borderRadius: 6,
|
||||||
|
backgroundColor: pressed ? theme.colors.surface1 : "transparent",
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
name={allCollapsed ? "ChevronsUpDown" : "ChevronsDownUp"}
|
||||||
|
size={13}
|
||||||
|
color={theme.colors.foregroundMuted}
|
||||||
|
/>
|
||||||
|
</Pressable>
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<ScrollView
|
||||||
|
style={{ flex: 1 }}
|
||||||
|
onScrollBeginDrag={closeContextMenu}
|
||||||
|
contentContainerStyle={{
|
||||||
|
padding: 10,
|
||||||
|
gap: 10,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{hostEntries.length === 0 ? (
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
paddingVertical: 24,
|
||||||
|
paddingHorizontal: 12,
|
||||||
|
alignItems: "center",
|
||||||
|
gap: 6,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Icon name="Server" size={20} color={theme.colors.foregroundMuted} />
|
||||||
|
<Text
|
||||||
|
style={{
|
||||||
|
fontSize: 13,
|
||||||
|
fontWeight: "500",
|
||||||
|
color: theme.colors.foreground,
|
||||||
|
textAlign: "center",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{activeOnly
|
||||||
|
? "No active workspaces"
|
||||||
|
: normalizedQuery
|
||||||
|
? "No matching hosts or workspaces"
|
||||||
|
: "No connected hosts"}
|
||||||
|
</Text>
|
||||||
|
<Text
|
||||||
|
style={{
|
||||||
|
fontSize: 12,
|
||||||
|
color: theme.colors.foregroundMuted,
|
||||||
|
textAlign: "center",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{activeOnly || normalizedQuery
|
||||||
|
? "Try clearing your filter to view all hosts."
|
||||||
|
: "Add or connect a Paseo host to see its workspaces here."}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
) : (
|
||||||
|
hostEntries.map((entry) => (
|
||||||
|
<HostGroup
|
||||||
|
key={entry.hostId}
|
||||||
|
hostId={entry.hostId}
|
||||||
|
hostLabel={entry.label}
|
||||||
|
hostStatus={entry.status}
|
||||||
|
workspaceRefs={entry.workspaceRefs}
|
||||||
|
projectRefs={entry.projectRefs}
|
||||||
|
agentsByWorkspace={agentsByWorkspace}
|
||||||
|
collapsed={collapsedHostIds.has(entry.hostId)}
|
||||||
|
onToggleCollapsed={toggleHostCollapsed}
|
||||||
|
theme={theme}
|
||||||
|
compact={layout.compact}
|
||||||
|
platform={layout.platform}
|
||||||
|
showAgents={showAgents}
|
||||||
|
activeWorkspaceKey={activeWorkspaceKey}
|
||||||
|
activeAgentKey={activeAgentKey}
|
||||||
|
activeMenuKey={activeMenuKey}
|
||||||
|
hasActiveWorkspaceInHost={activeHostId === entry.hostId}
|
||||||
|
onToggleMenu={toggleMenu}
|
||||||
|
onCloseMenu={closeMenu}
|
||||||
|
onOpenContextMenu={openContextMenu}
|
||||||
|
onOpenWorkspace={navigation.openWorkspace}
|
||||||
|
onOpenAgent={navigation.openAgent}
|
||||||
|
onOpenProject={navigation.openProject}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
<ContextMenuOverlay
|
||||||
|
request={contextMenu}
|
||||||
|
containerRef={rootRef}
|
||||||
|
platform={layout.platform}
|
||||||
|
theme={theme}
|
||||||
|
onClose={closeContextMenu}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,392 @@
|
|||||||
|
import type { PluginTheme } from "@getpaseo/plugin";
|
||||||
|
import { Icon, Modal, TextInput } from "@getpaseo/plugin/client/ui";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { Pressable, Text, View } from "react-native";
|
||||||
|
|
||||||
|
export interface RowIconButtonProps {
|
||||||
|
icon: string;
|
||||||
|
accessibilityLabel: string;
|
||||||
|
theme: PluginTheme;
|
||||||
|
size?: number;
|
||||||
|
paddingVertical?: number;
|
||||||
|
active?: boolean;
|
||||||
|
disabled?: boolean;
|
||||||
|
onPress(): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function RowIconButton({
|
||||||
|
icon,
|
||||||
|
accessibilityLabel,
|
||||||
|
theme,
|
||||||
|
size = 13,
|
||||||
|
paddingVertical = 6,
|
||||||
|
active = false,
|
||||||
|
disabled = false,
|
||||||
|
onPress,
|
||||||
|
}: RowIconButtonProps) {
|
||||||
|
return (
|
||||||
|
<Pressable
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel={accessibilityLabel}
|
||||||
|
disabled={disabled}
|
||||||
|
onPress={onPress}
|
||||||
|
style={({ pressed }) => ({
|
||||||
|
paddingHorizontal: 5,
|
||||||
|
paddingVertical,
|
||||||
|
borderRadius: 6,
|
||||||
|
backgroundColor:
|
||||||
|
active || pressed ? theme.colors.surface1 : "transparent",
|
||||||
|
opacity: disabled ? 0.5 : 1,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
name={icon}
|
||||||
|
size={size}
|
||||||
|
color={active ? theme.colors.foreground : theme.colors.foregroundMuted}
|
||||||
|
/>
|
||||||
|
</Pressable>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ActionPillProps {
|
||||||
|
icon: string;
|
||||||
|
label: string;
|
||||||
|
theme: PluginTheme;
|
||||||
|
tone?: "default" | "accent" | "danger";
|
||||||
|
disabled?: boolean;
|
||||||
|
onPress(): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ActionPill({
|
||||||
|
icon,
|
||||||
|
label,
|
||||||
|
theme,
|
||||||
|
tone = "default",
|
||||||
|
disabled = false,
|
||||||
|
onPress,
|
||||||
|
}: ActionPillProps) {
|
||||||
|
const foreground =
|
||||||
|
tone === "danger"
|
||||||
|
? theme.colors.statusDanger
|
||||||
|
: tone === "accent"
|
||||||
|
? theme.colors.accentForeground
|
||||||
|
: theme.colors.foreground;
|
||||||
|
const background =
|
||||||
|
tone === "accent" ? theme.colors.accent : theme.colors.surface2;
|
||||||
|
const borderColor =
|
||||||
|
tone === "danger"
|
||||||
|
? theme.colors.statusDanger
|
||||||
|
: tone === "accent"
|
||||||
|
? theme.colors.accent
|
||||||
|
: theme.colors.border;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Pressable
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel={label}
|
||||||
|
disabled={disabled}
|
||||||
|
onPress={onPress}
|
||||||
|
style={({ pressed }) => ({
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: 4,
|
||||||
|
paddingHorizontal: 8,
|
||||||
|
paddingVertical: 4,
|
||||||
|
borderRadius: 6,
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor,
|
||||||
|
backgroundColor: pressed ? theme.colors.surface1 : background,
|
||||||
|
opacity: disabled ? 0.5 : 1,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<Icon name={icon} size={12} color={foreground} />
|
||||||
|
<Text
|
||||||
|
style={{
|
||||||
|
fontSize: 11,
|
||||||
|
fontWeight: "600",
|
||||||
|
color: foreground,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{label}
|
||||||
|
</Text>
|
||||||
|
</Pressable>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RenameWorkspaceModalProps {
|
||||||
|
open: boolean;
|
||||||
|
initialTitle: string;
|
||||||
|
hasCustomTitle: boolean;
|
||||||
|
theme: PluginTheme;
|
||||||
|
saving: boolean;
|
||||||
|
onClose(): void;
|
||||||
|
onSave(nextTitle: string | null): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function RenameWorkspaceModal({
|
||||||
|
open,
|
||||||
|
initialTitle,
|
||||||
|
hasCustomTitle,
|
||||||
|
theme,
|
||||||
|
saving,
|
||||||
|
onClose,
|
||||||
|
onSave,
|
||||||
|
}: RenameWorkspaceModalProps) {
|
||||||
|
const [draft, setDraft] = useState(initialTitle);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (open) {
|
||||||
|
setDraft(initialTitle);
|
||||||
|
}
|
||||||
|
}, [open, initialTitle]);
|
||||||
|
|
||||||
|
const trimmed = draft.trim();
|
||||||
|
const canSave = !saving && trimmed.length > 0;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal
|
||||||
|
title="Rename workspace"
|
||||||
|
icon={<Icon name="Pencil" size={16} color={theme.colors.foreground} />}
|
||||||
|
open={open}
|
||||||
|
onOpenChange={(nextOpen) => {
|
||||||
|
if (!nextOpen && !saving) onClose();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Modal.Content>
|
||||||
|
<View style={{ gap: 12 }}>
|
||||||
|
<Text
|
||||||
|
style={{
|
||||||
|
fontSize: 13,
|
||||||
|
color: theme.colors.foregroundMuted,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Enter a title for this workspace, or reset to the default name.
|
||||||
|
</Text>
|
||||||
|
<TextInput
|
||||||
|
value={draft}
|
||||||
|
onChangeText={setDraft}
|
||||||
|
placeholder="Workspace title"
|
||||||
|
placeholderTextColor={theme.colors.foregroundMuted}
|
||||||
|
editable={!saving}
|
||||||
|
autoFocus
|
||||||
|
onSubmitEditing={() => {
|
||||||
|
if (canSave) onSave(trimmed);
|
||||||
|
}}
|
||||||
|
style={{
|
||||||
|
paddingHorizontal: 10,
|
||||||
|
paddingVertical: 8,
|
||||||
|
borderRadius: 8,
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: theme.colors.border,
|
||||||
|
backgroundColor: theme.colors.surface1,
|
||||||
|
color: theme.colors.foreground,
|
||||||
|
fontSize: 14,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "space-between",
|
||||||
|
gap: 8,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<View>
|
||||||
|
{hasCustomTitle ? (
|
||||||
|
<Pressable
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel="Reset to default title"
|
||||||
|
disabled={saving}
|
||||||
|
onPress={() => onSave(null)}
|
||||||
|
style={({ pressed }) => ({
|
||||||
|
paddingHorizontal: 10,
|
||||||
|
paddingVertical: 7,
|
||||||
|
borderRadius: 8,
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: theme.colors.border,
|
||||||
|
backgroundColor: pressed
|
||||||
|
? theme.colors.surface2
|
||||||
|
: theme.colors.surface1,
|
||||||
|
opacity: saving ? 0.5 : 1,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<Text
|
||||||
|
style={{
|
||||||
|
fontSize: 13,
|
||||||
|
fontWeight: "500",
|
||||||
|
color: theme.colors.foregroundMuted,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Reset
|
||||||
|
</Text>
|
||||||
|
</Pressable>
|
||||||
|
) : null}
|
||||||
|
</View>
|
||||||
|
<View style={{ flexDirection: "row", alignItems: "center", gap: 8 }}>
|
||||||
|
<Pressable
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel="Cancel rename"
|
||||||
|
disabled={saving}
|
||||||
|
onPress={onClose}
|
||||||
|
style={({ pressed }) => ({
|
||||||
|
paddingHorizontal: 12,
|
||||||
|
paddingVertical: 7,
|
||||||
|
borderRadius: 8,
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: theme.colors.border,
|
||||||
|
backgroundColor: pressed
|
||||||
|
? theme.colors.surface2
|
||||||
|
: theme.colors.surface1,
|
||||||
|
opacity: saving ? 0.5 : 1,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<Text
|
||||||
|
style={{
|
||||||
|
fontSize: 13,
|
||||||
|
fontWeight: "500",
|
||||||
|
color: theme.colors.foreground,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</Text>
|
||||||
|
</Pressable>
|
||||||
|
<Pressable
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel="Save workspace title"
|
||||||
|
disabled={!canSave}
|
||||||
|
onPress={() => {
|
||||||
|
if (canSave) onSave(trimmed);
|
||||||
|
}}
|
||||||
|
style={({ pressed }) => ({
|
||||||
|
paddingHorizontal: 14,
|
||||||
|
paddingVertical: 7,
|
||||||
|
borderRadius: 8,
|
||||||
|
backgroundColor: theme.colors.accent,
|
||||||
|
opacity: !canSave ? 0.5 : pressed ? 0.85 : 1,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<Text
|
||||||
|
style={{
|
||||||
|
fontSize: 13,
|
||||||
|
fontWeight: "600",
|
||||||
|
color: theme.colors.accentForeground,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{saving ? "Saving..." : "Save"}
|
||||||
|
</Text>
|
||||||
|
</Pressable>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</Modal.Content>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ConfirmArchiveModalProps {
|
||||||
|
open: boolean;
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
theme: PluginTheme;
|
||||||
|
archiving: boolean;
|
||||||
|
onClose(): void;
|
||||||
|
onConfirm(): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ConfirmArchiveModal({
|
||||||
|
open,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
theme,
|
||||||
|
archiving,
|
||||||
|
onClose,
|
||||||
|
onConfirm,
|
||||||
|
}: ConfirmArchiveModalProps) {
|
||||||
|
return (
|
||||||
|
<Modal
|
||||||
|
title={title}
|
||||||
|
icon={<Icon name="Archive" size={16} color={theme.colors.statusDanger} />}
|
||||||
|
open={open}
|
||||||
|
onOpenChange={(nextOpen) => {
|
||||||
|
if (!nextOpen && !archiving) onClose();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Modal.Content>
|
||||||
|
<View style={{ gap: 14 }}>
|
||||||
|
<Text
|
||||||
|
style={{
|
||||||
|
fontSize: 13,
|
||||||
|
lineHeight: 18,
|
||||||
|
color: theme.colors.foregroundMuted,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{description}
|
||||||
|
</Text>
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "flex-end",
|
||||||
|
gap: 8,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Pressable
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel="Cancel archive"
|
||||||
|
disabled={archiving}
|
||||||
|
onPress={onClose}
|
||||||
|
style={({ pressed }) => ({
|
||||||
|
paddingHorizontal: 12,
|
||||||
|
paddingVertical: 7,
|
||||||
|
borderRadius: 8,
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: theme.colors.border,
|
||||||
|
backgroundColor: pressed
|
||||||
|
? theme.colors.surface2
|
||||||
|
: theme.colors.surface1,
|
||||||
|
opacity: archiving ? 0.5 : 1,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<Text
|
||||||
|
style={{
|
||||||
|
fontSize: 13,
|
||||||
|
fontWeight: "500",
|
||||||
|
color: theme.colors.foreground,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</Text>
|
||||||
|
</Pressable>
|
||||||
|
<Pressable
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel="Confirm archive"
|
||||||
|
disabled={archiving}
|
||||||
|
onPress={onConfirm}
|
||||||
|
style={({ pressed }) => ({
|
||||||
|
paddingHorizontal: 14,
|
||||||
|
paddingVertical: 7,
|
||||||
|
borderRadius: 8,
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: theme.colors.statusDanger,
|
||||||
|
backgroundColor: pressed
|
||||||
|
? theme.colors.surface1
|
||||||
|
: theme.colors.surface2,
|
||||||
|
opacity: archiving ? 0.5 : 1,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<Text
|
||||||
|
style={{
|
||||||
|
fontSize: 13,
|
||||||
|
fontWeight: "600",
|
||||||
|
color: theme.colors.statusDanger,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{archiving ? "Archiving..." : "Archive"}
|
||||||
|
</Text>
|
||||||
|
</Pressable>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</Modal.Content>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -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>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import type { PluginClientContext } from "@getpaseo/plugin/client";
|
||||||
|
import { HostGroupedSidebarView } from "./client/host-sidebar-view";
|
||||||
|
|
||||||
|
export default function contribute(client: PluginClientContext) {
|
||||||
|
const disposeSidebarView = client.addSidebarView({
|
||||||
|
id: "hosts",
|
||||||
|
title: "Group by host",
|
||||||
|
description: "Group workspaces, agents, and projects by connected host",
|
||||||
|
Component: HostGroupedSidebarView,
|
||||||
|
});
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
disposeSidebarView();
|
||||||
|
};
|
||||||
|
}
|
||||||
Generated
+4147
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"name": "group-by-host",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.0.0",
|
||||||
|
"files": [
|
||||||
|
"paseo-plugin.json",
|
||||||
|
"OVERVIEW.md",
|
||||||
|
"OVERVIEW.*.md",
|
||||||
|
"index.client.ts",
|
||||||
|
"index.client.tsx",
|
||||||
|
"client/"
|
||||||
|
],
|
||||||
|
"scripts": {
|
||||||
|
"typecheck": "tsc --noEmit"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@getpaseo/plugin": "0.16.1",
|
||||||
|
"@tanstack/react-query": "^5.90.11",
|
||||||
|
"@types/react": "~19.2.0",
|
||||||
|
"react": "19.1.0",
|
||||||
|
"react-native": "0.81.5",
|
||||||
|
"typescript": "^5.9.3",
|
||||||
|
"zod": "^4.4.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"id": "group-by-host",
|
||||||
|
"name": "Group by host",
|
||||||
|
"description": "Sidebar view that groups workspaces, agents, and projects by connected Paseo host.",
|
||||||
|
"media": [],
|
||||||
|
"requirements": {
|
||||||
|
"paseo": ">=0.16.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2020",
|
||||||
|
"module": "ESNext",
|
||||||
|
"moduleResolution": "Bundler",
|
||||||
|
"lib": [
|
||||||
|
"ES2023"
|
||||||
|
],
|
||||||
|
"types": [
|
||||||
|
"react"
|
||||||
|
],
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
"strict": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"noEmit": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"allowSyntheticDefaultImports": true
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"**/*.ts",
|
||||||
|
"**/*.tsx"
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in new issue
Block a user