import React, { useState, useEffect } from "react"; import { motion } from "framer-motion"; import { Settings, Save, Trash2, HardDrive, AlertCircle } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Label } from "@/components/ui/label"; import { Switch } from "@/components/ui/switch"; import { SelectComponent, type SelectOption } from "@/components/ui/select"; import { Input } from "@/components/ui/input"; import { api, type CheckpointStrategy } from "@/lib/api"; import { cn } from "@/lib/utils"; interface CheckpointSettingsProps { sessionId: string; projectId: string; projectPath: string; onClose?: () => void; className?: string; } /** * CheckpointSettings component for managing checkpoint configuration * * @example * */ export const CheckpointSettings: React.FC = ({ sessionId, projectId, projectPath, onClose, className, }) => { const [autoCheckpointEnabled, setAutoCheckpointEnabled] = useState(true); const [checkpointStrategy, setCheckpointStrategy] = useState("smart"); const [totalCheckpoints, setTotalCheckpoints] = useState(0); const [keepCount, setKeepCount] = useState(10); const [isLoading, setIsLoading] = useState(false); const [isSaving, setIsSaving] = useState(false); const [error, setError] = useState(null); const [successMessage, setSuccessMessage] = useState(null); const strategyOptions: SelectOption[] = [ { value: "manual", label: "Manual Only" }, { value: "per_prompt", label: "After Each Prompt" }, { value: "per_tool_use", label: "After Tool Use" }, { value: "smart", label: "Smart (Recommended)" }, ]; useEffect(() => { loadSettings(); }, [sessionId, projectId, projectPath]); const loadSettings = async () => { try { setIsLoading(true); setError(null); const settings = await api.getCheckpointSettings(sessionId, projectId, projectPath); setAutoCheckpointEnabled(settings.auto_checkpoint_enabled); setCheckpointStrategy(settings.checkpoint_strategy); setTotalCheckpoints(settings.total_checkpoints); } catch (err) { console.error("Failed to load checkpoint settings:", err); setError("Failed to load checkpoint settings"); } finally { setIsLoading(false); } }; const handleSaveSettings = async () => { try { setIsSaving(true); setError(null); setSuccessMessage(null); await api.updateCheckpointSettings( sessionId, projectId, projectPath, autoCheckpointEnabled, checkpointStrategy ); setSuccessMessage("Settings saved successfully"); setTimeout(() => setSuccessMessage(null), 3000); } catch (err) { console.error("Failed to save checkpoint settings:", err); setError("Failed to save checkpoint settings"); } finally { setIsSaving(false); } }; const handleCleanup = async () => { try { setIsLoading(true); setError(null); setSuccessMessage(null); const removed = await api.cleanupOldCheckpoints( sessionId, projectId, projectPath, keepCount ); setSuccessMessage(`Removed ${removed} old checkpoints`); setTimeout(() => setSuccessMessage(null), 3000); // Reload settings to get updated count await loadSettings(); } catch (err) { console.error("Failed to cleanup checkpoints:", err); setError("Failed to cleanup checkpoints"); } finally { setIsLoading(false); } }; return (

Checkpoint Settings

{onClose && ( )}
{/* Experimental Feature Warning */}

Experimental Feature

Checkpointing may affect directory structure or cause data loss. Use with caution.

{error && (
{error}
)} {successMessage && ( {successMessage} )}
{/* Auto-checkpoint toggle */}

Automatically create checkpoints based on the selected strategy

{/* Checkpoint strategy */}
setCheckpointStrategy(value as CheckpointStrategy)} options={strategyOptions} disabled={isLoading || !autoCheckpointEnabled} />

{checkpointStrategy === "manual" && "Checkpoints will only be created manually"} {checkpointStrategy === "per_prompt" && "A checkpoint will be created after each user prompt"} {checkpointStrategy === "per_tool_use" && "A checkpoint will be created after each tool use"} {checkpointStrategy === "smart" && "Checkpoints will be created after destructive operations"}

{/* Save button */}

Total checkpoints: {totalCheckpoints}

{/* Cleanup settings */}
setKeepCount(parseInt(e.target.value) || 10)} disabled={isLoading} className="flex-1" />

Remove old checkpoints, keeping only the most recent {keepCount}

); };