From b8400ea7bc8c03dda4da70978d09258deac51ef5 Mon Sep 17 00:00:00 2001 From: facyndev Date: Tue, 6 Oct 2026 18:47:44 -0300 Subject: [PATCH 01/71] feat(desktop): position terminal duration badge at top right with container style and add thread gap --- apps/desktop/src/components/Sidebar.tsx | 5 ++- apps/desktop/src/components/ThreadMeta.css | 50 +++++++++++++++++++++- apps/desktop/src/components/ThreadMeta.tsx | 7 ++- apps/desktop/src/styles.css | 14 +++++- 4 files changed, 71 insertions(+), 5 deletions(-) diff --git a/apps/desktop/src/components/Sidebar.tsx b/apps/desktop/src/components/Sidebar.tsx index bee2c73..80b5ee8 100644 --- a/apps/desktop/src/components/Sidebar.tsx +++ b/apps/desktop/src/components/Sidebar.tsx @@ -180,11 +180,14 @@ export function Sidebar(props: Props) { const { tone, label: stateLabel } = describeAgent(agentState, attention); const branch = m?.branch ?? null; const select = () => props.onSelectTerminal(s.id, pane.id); + const hasUptime = agent !== null && m?.startedAt != null; return (
  • + ); +} + +type IconButtonProps = Omit, "type" | "children"> & { + icon: ReactNode; + /// Obligatorio: es el tooltip y el nombre accesible (no hay texto visible). + title: string; +}; + +/// Botón de solo ícono (minimizar, cerrar, agregar, ajustes…). +export function IconButton({ icon, title, className, ...rest }: IconButtonProps) { + return ( + + ); +} diff --git a/packages/ui/src/components/Panel.tsx b/packages/ui/src/components/Panel.tsx new file mode 100644 index 0000000..cb8fecd --- /dev/null +++ b/packages/ui/src/components/Panel.tsx @@ -0,0 +1,48 @@ +import type { HTMLAttributes, ReactNode, Ref } from "react"; + +type Props = Omit, "children"> & { + /// Elemento raíz (para semántica: `section` en un panel de terminal, `div` en una lista). + as?: "section" | "div"; + ref?: Ref; + /// Barra de título: va sobre el fondo del wrapper. + header: ReactNode; + /// Contenido del bloque interno (oscuro y con radio). Sin `children` ni + /// `bodyRef` no se dibuja el bloque. + children?: ReactNode; + bodyRef?: Ref; + bodyClassName?: string; + /// Sin marco: solo el contenido, sin fondo ni borde (p. ej. una sesión inactiva). + plain?: boolean; +}; + +/// Wrapper visual de la app: un marco con la barra de título arriba y el +/// contenido en un bloque interno oscuro con radio, envuelto por el padding +/// del marco. Lo usan el panel de una terminal y la sesión del sidebar. +export function Panel({ + as: Root = "section", + ref, + header, + children, + bodyRef, + bodyClassName, + plain = false, + className, + ...rest +}: Props) { + const hasBody = children !== undefined || bodyRef !== undefined; + const classes = ["panel", plain && "panel--plain", className].filter(Boolean).join(" "); + return ( + } + className={classes} + {...(rest as HTMLAttributes)} + > + {header} + {hasBody && ( +
    + {children} +
    + )} +
    + ); +} diff --git a/packages/ui/src/components/Sidebar.tsx b/packages/ui/src/components/Sidebar.tsx new file mode 100644 index 0000000..0e60784 --- /dev/null +++ b/packages/ui/src/components/Sidebar.tsx @@ -0,0 +1,308 @@ +import { useEffect, useRef, useState } from "react"; + +import { VscTerminal } from "react-icons/vsc"; + +import { agentInfo } from "../agents"; +import { opencollabLogoRounded } from "../brand"; +import { initialsOf, type AuthState } from "../authTypes"; +import { Check, ChevronDown, ChevronsUpDown, Plus, Search, SignOut } from "../icons"; +import { + sessionSummary, + type PaneMeta, + type PaneStatus, + type Workspace, +} from "../model"; +import { modKey } from "../shortcuts"; +import { Button, IconButton } from "./Button"; +import { Panel } from "./Panel"; +import { TerminalIcon } from "./TerminalIcon"; +import { describeAgent } from "../agentState"; +import { ThreadBranch, ThreadMeta, ThreadState } from "./ThreadMeta"; + +type Props = { + workspaces: Workspace[]; + activeWorkspace: Workspace; + activeSessionId: string; + focusedPaneId: string | null; + statuses: Record; + meta: Record; + searchRef: React.RefObject; + onSelectWorkspace: (id: string) => void; + onCreateWorkspace: () => void; + onSelectSession: (id: string) => void; + onSelectTerminal: (sessionId: string, paneId: string) => void; + onCreateSession: () => void; + auth: AuthState; + authBusy: boolean; + authError: string | null; + loginUrl: string | null; + onSignIn: () => void; + onCancelLogin: () => void; + onSignOut: () => void; +}; + +export function Sidebar(props: Props) { + const { workspaces, activeWorkspace, activeSessionId, statuses, meta } = props; + const [switcherOpen, setSwitcherOpen] = useState(false); + const [query, setQuery] = useState(""); + const switcherRef = useRef(null); + + useEffect(() => { + if (!switcherOpen) return; + const close = (e: MouseEvent) => { + if (!switcherRef.current?.contains(e.target as Node)) setSwitcherOpen(false); + }; + document.addEventListener("mousedown", close); + return () => document.removeEventListener("mousedown", close); + }, [switcherOpen]); + + const sessions = activeWorkspace.sessions.filter((s) => + s.name.toLowerCase().includes(query.trim().toLowerCase()), + ); + + return ( + + ); +} + +function AuthCard(props: { + auth: AuthState; + busy: boolean; + error: string | null; + loginUrl: string | null; + onSignIn: () => void; + onCancelLogin: () => void; + onSignOut: () => void; +}) { + const { auth, busy } = props; + if (auth.status === "authenticated") { + return ( +
    + {initialsOf(auth.user)} + + {auth.user.displayName || auth.user.username} + + Online + + + } title="Sign out" onClick={props.onSignOut} /> +
    + ); + } + return ( +
    + + + {auth.status === "unknown" ? "Loading…" : busy ? "Waiting for browser…" : "Not signed in"} + + {props.error ? ( + + {props.error} + + ) : ( + + {busy ? "Finish sign-in in your browser" : "Sign in to collaborate"} + + )} + + {busy ? ( + + ) : ( + + )} + {busy && props.loginUrl ? ( + + Browser didn't open? Open manually + + ) : undefined} + +
    + ); +} diff --git a/packages/ui/src/components/StatusBar.tsx b/packages/ui/src/components/StatusBar.tsx new file mode 100644 index 0000000..38ccec1 --- /dev/null +++ b/packages/ui/src/components/StatusBar.tsx @@ -0,0 +1,33 @@ +import { DEFAULT_COLLAB_STATUS } from "../collabStatus"; +import { modKey, shiftKey } from "../shortcuts"; + +type Props = { + connected?: boolean; + syncMs?: number | null; + collaborators?: number; +}; + +export function StatusBar({ + connected = DEFAULT_COLLAB_STATUS.connected, + syncMs = DEFAULT_COLLAB_STATUS.syncMs, + collaborators = DEFAULT_COLLAB_STATUS.collaborators, +}: Props = {}) { + return ( +
    + + + {connected ? ( + <>Connected{syncMs != null ? ` · sync ${syncMs}ms` : ""} + ) : ( + "Local · relay no conectado" + )} + + + {collaborators} {collaborators === 1 ? "collaborator" : "collaborators"} + + + {modKey}T new · {modKey}1-4 focus · {modKey}{shiftKey}M maximize + +
    + ); +} diff --git a/packages/ui/src/components/TerminalIcon.tsx b/packages/ui/src/components/TerminalIcon.tsx new file mode 100644 index 0000000..517591a --- /dev/null +++ b/packages/ui/src/components/TerminalIcon.tsx @@ -0,0 +1,44 @@ +import type { IconType } from "react-icons"; +import { VscTerminal, VscTerminalBash, VscTerminalCmd, VscTerminalPowershell } from "react-icons/vsc"; + +import { agentInfo, type AgentId } from "../agents"; + +/// Ícono de la shell cuando no corre ningún agente conocido. +function shellIcon(name: string): IconType { + const n = name.toLowerCase(); + if (n.includes("powershell") || n === "pwsh") return VscTerminalPowershell; + if (n === "cmd" || n.includes("command prompt")) return VscTerminalCmd; + if (n.includes("bash") || n.includes("zsh") || n === "sh") return VscTerminalBash; + return VscTerminal; +} + +type Props = { + /// Agente detectado en la terminal (`null` = solo la shell). + agent: AgentId | null; + shellName: string; + /// Tamaño en px (cuadrado). + size?: number; +}; + +/// Lo que corre en una terminal: el logo del agente detectado o, si no hay +/// ninguno, el ícono de la shell. Lo usan el header del panel y el sidebar. +export function TerminalIcon({ agent, shellName, size = 18 }: Props) { + const box = { width: size, height: size }; + if (agent) { + const info = agentInfo(agent); + if (info.logo) { + // Máscara en vez de : el SVG aporta la forma y el color sale del token --text. + return ( + + ); + } + return {info.badge}; + } + const Icon = shellIcon(shellName); + return
  • + +
  • + ); +} + +function StateIcon({ tone }: { tone: string }) { + if (tone === "attention") return