Initial release v0.2.5

This commit is contained in:
Chris Scott committed 2025-11-23 23:25:27 -05:00
commit bbf66c259b
158 files changed
+37115

No files matched your search

@@ -0,0 +1,96 @@
import { useContextUsage } from '@/hooks/useContextUsage'
import { getModel, formatModelName } from '@/api/providers'
import { useSettings } from '@/hooks/useSettings'
import { useState, useEffect } from 'react'
interface ContextUsageIndicatorProps {
opcodeUrl: string | null
sessionID: string | undefined
directory?: string
}
export function ContextUsageIndicator({ opcodeUrl, sessionID, directory }: ContextUsageIndicatorProps) {
const { totalTokens, contextLimit, usagePercentage, currentModel, isLoading } = useContextUsage(opcodeUrl, sessionID, directory)
const { preferences } = useSettings()
const [modelName, setModelName] = useState<string>('')
const displayModel = preferences?.defaultModel || currentModel || ''
useEffect(() => {
const loadModelName = async () => {
if (displayModel) {
try {
const [providerId, modelId] = displayModel.split('/')
if (providerId && modelId) {
const model = await getModel(providerId, modelId)
if (model) {
setModelName(formatModelName(model))
} else {
setModelName(displayModel)
}
} else {
setModelName(displayModel)
}
} catch {
setModelName(displayModel)
}
} else {
setModelName('')
}
}
loadModelName()
}, [displayModel, opcodeUrl])
if (isLoading) {
return (
<div className="flex items-center gap-2">
<span className="text-xs text-muted-foreground">Loading...</span>
</div>
)
}
if (!modelName) {
return (
<div className="flex items-center gap-2">
<span className="text-xs text-muted-foreground">No model</span>
</div>
)
}
const getUsageColor = (percentage: number) => {
if (percentage < 50) return 'bg-green-700 dark:bg-green-400'
if (percentage < 80) return 'bg-yellow-700 dark:bg-yellow-400'
return 'bg-red-700 dark:bg-red-400'
}
const getUsageTextColor = (percentage: number) => {
if (percentage < 50) return 'text-green-700 dark:text-green-400'
if (percentage < 80) return 'text-yellow-700 dark:text-yellow-400'
return 'text-red-700 dark:text-red-400'
}
if (!contextLimit) {
return (
<div className="flex items-center gap-2">
<span className="text-xs text-muted-foreground">{modelName}</span>
</div>
)
}
return (
<div className="flex items-center gap-2">
<div className="flex items-center gap-2 min-w-0">
<div className="w-16 h-2 bg-muted rounded-full overflow-hidden border border-border">
<div
className={`h-full transition-all duration-300 ${getUsageColor(usagePercentage || 0)}`}
style={{ width: `${Math.min(usagePercentage || 0, 100)}%` }}
/>
</div>
<span className={`text-xs font-medium whitespace-nowrap ${getUsageTextColor(usagePercentage || 0)}`}>
{totalTokens.toLocaleString()} / {contextLimit.toLocaleString()}
</span>
</div>
</div>
)
}
@@ -0,0 +1,30 @@
import { DeleteDialog } from '@/components/ui/delete-dialog'
interface DeleteSessionDialogProps {
open: boolean
onOpenChange: (open: boolean) => void
onConfirm: () => void
onCancel: () => void
isDeleting?: boolean
sessionCount?: number
}
export function DeleteSessionDialog({ open, onOpenChange, onConfirm, onCancel, isDeleting = false, sessionCount = 1 }: DeleteSessionDialogProps) {
const isMultiple = sessionCount > 1
const title = isMultiple ? "Delete Sessions" : "Delete Session"
const description = isMultiple
? `Are you sure you want to delete ${sessionCount} sessions? This action cannot be undone.`
: "Are you sure you want to delete this session? This action cannot be undone."
return (
<DeleteDialog
open={open}
onOpenChange={onOpenChange}
onConfirm={onConfirm}
onCancel={onCancel}
title={title}
description={description}
isDeleting={isDeleting}
/>
)
}
@@ -0,0 +1,116 @@
import { BackButton } from "@/components/ui/back-button";
import { ContextUsageIndicator } from "@/components/session/ContextUsageIndicator";
import { BranchSwitcher } from "@/components/repo/BranchSwitcher";
import { Button } from "@/components/ui/button";
import { Loader2, Settings, FolderOpen } from "lucide-react";
interface Repo {
id: number;
repoUrl: string;
fullPath: string;
localPath: string;
currentBranch?: string;
isWorktree?: boolean;
cloneStatus: 'ready' | 'cloning' | 'error';
}
interface SessionDetailHeaderProps {
repo: Repo;
sessionId: string;
sessionTitle: string;
repoId: number;
isConnected: boolean;
opcodeUrl: string | null;
repoDirectory: string | undefined;
onFileBrowserOpen: () => void;
onSettingsOpen: () => void;
onShowModelsDialog?: () => void;
}
export function SessionDetailHeader({
repo,
sessionId,
sessionTitle,
repoId,
isConnected,
opcodeUrl,
repoDirectory,
onFileBrowserOpen,
onSettingsOpen,
}: SessionDetailHeaderProps) {
if (repo.cloneStatus !== 'ready') {
return (
<div className="sticky top-0 z-10 border-b border-border bg-gradient-to-b from-background via-background to-background backdrop-blur-sm px-2 sm:px-4 py-1.5 sm:py-2">
<div className="flex items-center justify-center">
<Loader2 className="w-4 h-4 animate-spin text-muted-foreground mr-2" />
<span className="text-sm text-muted-foreground">
{repo.cloneStatus === 'cloning' ? 'Cloning repository...' : 'Repository not ready'}
</span>
</div>
</div>
);
}
const repoName = repo.repoUrl.split("/").pop()?.replace(".git", "") || "Repository";
const currentBranch = repo.currentBranch || "main";
return (
<div className="sticky top-0 z-10 border-b border-border bg-gradient-to-b from-background via-background to-background backdrop-blur-sm px-2 sm:px-4 py-1.5 sm:py-2">
<div className="flex items-center justify-between gap-2">
<div className="flex items-center gap-1.5 sm:gap-3 min-w-0 flex-1">
<BackButton to={`/repos/${repoId}`} className="text-xs sm:text-sm" />
<div className="min-w-0 flex-1">
<h1 className="text-xs sm:text-base font-semibold bg-gradient-to-r from-foreground to-muted-foreground bg-clip-text text-transparent truncate">
{sessionTitle}
</h1>
<div className="flex items-center gap-2">
<p className="text-[10px] sm:text-xs text-muted-foreground truncate">
{repoName}
</p>
<BranchSwitcher
repoId={repoId}
currentBranch={currentBranch}
isWorktree={repo.isWorktree}
repoUrl={repo.repoUrl}
/>
</div>
</div>
</div>
<div className="flex items-center gap-2 sm:gap-4 flex-shrink-0">
<div className="hidden sm:block">
<ContextUsageIndicator
opcodeUrl={opcodeUrl}
sessionID={sessionId}
directory={repoDirectory}
/>
</div>
<div className="flex items-center gap-1 sm:gap-2">
<div
className={`w-1.5 h-1.5 sm:w-2 sm:h-2 rounded-full ${isConnected ? "bg-green-500" : "bg-red-500"}`}
/>
<span className="text-xs text-muted-foreground hidden sm:inline">
{isConnected ? "Connected" : "Disconnected"}
</span>
</div>
<Button
variant="ghost"
size="icon"
onClick={onFileBrowserOpen}
className="text-muted-foreground hover:text-foreground hover:bg-accent transition-all duration-200 h-8 w-8"
>
<FolderOpen className="w-4 h-4" />
</Button>
<Button
variant="ghost"
size="icon"
onClick={onSettingsOpen}
className="text-muted-foreground hover:text-foreground hover:bg-accent transition-all duration-200 h-8 w-8"
>
<Settings className="w-4 h-4" />
</Button>
</div>
</div>
</div>
);
}
@@ -0,0 +1,237 @@
import { useState, useMemo } from "react";
import { useSessions, useDeleteSession } from "@/hooks/useOpenCode";
import { Card } from "@/components/ui/card";
import { Input } from "@/components/ui/input";
import { Button } from "@/components/ui/button";
import { DeleteSessionDialog } from "./DeleteSessionDialog";
import { Trash2, GitBranch, Clock, Search } from "lucide-react";
import { formatDistanceToNow } from "date-fns";
interface SessionListProps {
opcodeUrl: string;
directory?: string;
activeSessionID?: string;
onSelectSession: (sessionID: string) => void;
}
export const SessionList = ({
opcodeUrl,
directory,
activeSessionID,
onSelectSession,
}: SessionListProps) => {
const { data: sessions, isLoading } = useSessions(opcodeUrl, directory);
const deleteSession = useDeleteSession(opcodeUrl, directory);
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
const [sessionToDelete, setSessionToDelete] = useState<
string | string[] | null
>(null);
const [searchQuery, setSearchQuery] = useState("");
const [selectedSessions, setSelectedSessions] = useState<Set<string>>(
new Set(),
);
const filteredSessions = useMemo(() => {
if (!sessions) return [];
if (!searchQuery.trim()) return sessions;
const query = searchQuery.toLowerCase();
return sessions.filter((session) =>
(session.title || "Untitled Session").toLowerCase().includes(query),
);
}, [sessions, searchQuery]);
if (isLoading) {
return <div className="p-4 text-sm text-gray-400">Loading sessions...</div>;
}
if (!sessions || sessions.length === 0) {
return (
<div className="p-4 text-sm text-gray-400">
No sessions yet. Create one to get started.
</div>
);
}
const handleDelete = (
sessionId: string,
e: React.MouseEvent<HTMLButtonElement>,
) => {
e.stopPropagation();
setSessionToDelete(sessionId);
setDeleteDialogOpen(true);
};
const confirmDelete = async () => {
if (sessionToDelete) {
await deleteSession.mutateAsync(sessionToDelete);
setDeleteDialogOpen(false);
setSessionToDelete(null);
setSelectedSessions(new Set());
}
};
const cancelDelete = () => {
setDeleteDialogOpen(false);
setSessionToDelete(null);
};
const toggleSessionSelection = (sessionId: string, selected: boolean) => {
const newSelected = new Set(selectedSessions);
if (selected) {
newSelected.add(sessionId);
} else {
newSelected.delete(sessionId);
}
setSelectedSessions(newSelected);
};
const toggleSelectAll = () => {
if (!filteredSessions || filteredSessions.length === 0) return;
const allFilteredSelected = filteredSessions.every((session) =>
selectedSessions.has(session.id),
);
if (allFilteredSelected) {
setSelectedSessions(new Set());
} else {
const filteredIds = filteredSessions.map((s) => s.id);
setSelectedSessions(new Set([...selectedSessions, ...filteredIds]));
}
};
const handleBulkDelete = () => {
if (selectedSessions.size > 0) {
setSessionToDelete(Array.from(selectedSessions));
setDeleteDialogOpen(true);
}
};
return (
<div className="flex flex-col h-full">
<div className="p-4 flex-shrink-0">
<div className="flex items-center gap-3 mb-3">
<div className="relative flex-1">
<Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400" />
<Input
type="text"
placeholder="Search"
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
className="pl-10"
/>
</div>
{filteredSessions && filteredSessions.length > 0 && (
<Button
onClick={toggleSelectAll}
variant={selectedSessions.size > 0 ? "default" : "outline"}
className="whitespace-nowrap"
>
{filteredSessions.every((session) =>
selectedSessions.has(session.id),
)
? "Deselect All"
: "Select All"}
</Button>
)}
<Button
onClick={handleBulkDelete}
variant="destructive"
disabled={selectedSessions.size === 0}
className="hidden md:flex whitespace-nowrap"
>
<Trash2 className="w-4 h-4 mr-2" />
Delete ({selectedSessions.size})
</Button>
<Button
onClick={handleBulkDelete}
variant="destructive"
disabled={selectedSessions.size === 0}
size="icon"
className="md:hidden"
>
<Trash2 className="w-4 h-4" />
</Button>
</div>
</div>
<div className="flex-1 overflow-y-auto px-4 pb-4">
<div className="flex flex-col gap-2">
{filteredSessions.length === 0 ? (
<div className="text-sm text-gray-400 text-center py-4">
No sessions found
</div>
) : (
filteredSessions.map((session) => (
<Card
key={session.id}
className={`p-3 cursor-pointer transition-all ${
selectedSessions.has(session.id)
? "border-blue-500 shadow-lg shadow-blue-900/30 bg-[#2a2a2a]"
: activeSessionID === session.id
? "bg-[#333333] border-[#5a5a5a]"
: "bg-[#2a2a2a] border-[#4a4a4a] hover:bg-[#333333] hover:border-[#5a5a5a]"
} hover:shadow-lg`}
onClick={() => onSelectSession(session.id)}
>
<div className="flex items-start justify-between gap-2">
<div className="flex items-start gap-2 flex-1 min-w-0">
<input
type="checkbox"
checked={selectedSessions.has(session.id)}
onChange={(e) => {
e.stopPropagation();
toggleSessionSelection(session.id, e.target.checked);
}}
onClick={(e) => {
e.stopPropagation();
}}
className="w-5 h-5 rounded border-gray-600 accent-blue-500 cursor-pointer flex-shrink-0 mt-0.5"
/>
<div className="flex-1 min-w-0">
<h3 className="text-sm font-medium text-white truncate">
{session.title || "Untitled Session"}
</h3>
<div className="flex items-center gap-3 mt-1 text-xs text-gray-400">
{session.parentID && (
<span className="flex items-center gap-1">
<GitBranch className="w-3 h-3" />
Forked
</span>
)}
<span className="flex items-center gap-1">
<Clock className="w-3 h-3" />
{formatDistanceToNow(new Date(session.time.updated), {
addSuffix: true,
})}
</span>
</div>
</div>
</div>
<button
className="h-6 w-6 p-0 text-gray-400 hover:text-red-400 bg-transparent border-none cursor-pointer"
onClick={(e) => handleDelete(session.id, e)}
>
<Trash2 className="w-4 h-4" />
</button>
</div>
</Card>
))
)}
</div>
</div>
<DeleteSessionDialog
open={deleteDialogOpen}
onOpenChange={setDeleteDialogOpen}
onConfirm={confirmDelete}
onCancel={cancelDelete}
isDeleting={deleteSession.isPending}
sessionCount={
Array.isArray(sessionToDelete) ? sessionToDelete.length : 1
}
/>
</div>
);
};