DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
fix: web lint
Bingxi Zhao3f40ce430108
diff --git a/web/.env.local b/web/.env.localindex 8840a64d6..0b6543af3 100644--- a/web/.env.local+++ b/web/.env.local@@ -3,7 +3,7 @@# ============================================# This file is automatically updated based on config/main.yaml# and environment variables (NEXT_PUBLIC_API_BASE, NEXT_PUBLIC_API_BASE_EXTERNAL)-#+## To configure for remote access, set in your .env file:# NEXT_PUBLIC_API_BASE=http://your-server-ip:8001# ============================================diff --git a/web/app/guide/page.tsx b/web/app/guide/page.tsxindex 3a30b1e3f..b02480a80 100644--- a/web/app/guide/page.tsx+++ b/web/app/guide/page.tsx@@ -174,7 +174,7 @@ export default function GuidePage() {<p className="text-sm text-slate-400 dark:text-slate-500 max-w-md text-center leading-relaxed">Select a notebook, and the system will generate a personalizedlearning plan. Through interactive pages and intelligent Q&A,- you'll gradually master all the content.+ you'll gradually master all the content.</p></div>) : isCompleted ? (diff --git a/web/app/history/page.tsx b/web/app/history/page.tsxindex d416d5dae..3a328bc07 100644--- a/web/app/history/page.tsx+++ b/web/app/history/page.tsx@@ -1,6 +1,6 @@"use client";-import { useState, useEffect } from "react";+import { useState, useEffect, useCallback } from "react";import { useRouter } from "next/navigation";import {History,@@ -86,11 +86,7 @@ export default function HistoryPage() {const [filterType, setFilterType] = useState<string>("all");const [searchQuery, setSearchQuery] = useState("");- useEffect(() => {- fetchHistory();- }, [filterType]);-- const fetchHistory = async () => {+ const fetchHistory = useCallback(async () => {setLoading(true);try {// Fetch regular activity history@@ -125,7 +121,11 @@ export default function HistoryPage() {} finally {setLoading(false);}- };+ }, [filterType]);++ useEffect(() => {+ fetchHistory();+ }, [fetchHistory]);const handleLoadChatSession = async (sessionId: string) => {setLoadingSessionId(sessionId);diff --git a/web/app/knowledge/page.tsx b/web/app/knowledge/page.tsxindex a319d48d0..66a0e68e7 100644--- a/web/app/knowledge/page.tsx+++ b/web/app/knowledge/page.tsx@@ -744,7 +744,7 @@ export default function KnowledgePage() {});kbsNamesRef.current = kbs.map((kb) => kb.name);- // eslint-disable-next-line react-hooks/exhaustive-deps+}, [kbs, loading]);// Cleanup all connections on component unmount@@ -943,6 +943,7 @@ export default function KnowledgePage() {addFiles(validFiles);}}+ // eslint-disable-next-line react-hooks/exhaustive-deps -- Helper functions are stable}, []);return (diff --git a/web/app/research/page.tsx b/web/app/research/page.tsxindex 5c633e79c..d6d092d42 100644--- a/web/app/research/page.tsx+++ b/web/app/research/page.tsx@@ -92,6 +92,7 @@ export default function ResearchPage() {}}).catch((err) => console.error("Failed to fetch KBs:", err));+ // eslint-disable-next-line react-hooks/exhaustive-deps -- Only run on mount}, []);// Auto-scroll Chat@@ -116,6 +117,7 @@ export default function ResearchPage() {},]);}+ // eslint-disable-next-line react-hooks/exhaustive-deps -- Only run on mount to set initial greeting}, []);// Select latest active task automatically if none selecteddiff --git a/web/app/settings/components/ConfigTab.tsx b/web/app/settings/components/ConfigTab.tsxindex 0e995de4f..0cf0750b1 100644--- a/web/app/settings/components/ConfigTab.tsx+++ b/web/app/settings/components/ConfigTab.tsx@@ -1,6 +1,6 @@"use client";-import { useState, useEffect } from "react";+import { useState, useEffect, useCallback } from "react";import { Plus, Trash2, Loader2, Pencil } from "lucide-react";import { apiUrl } from "@/lib/api";import { ConfigItem, ConfigType } from "../types";@@ -35,11 +35,7 @@ export default function ConfigTab({message: string;} | null>(null);- useEffect(() => {- loadConfigs();- }, [configType]);-- const loadConfigs = async () => {+ const loadConfigs = useCallback(async () => {try {const res = await fetch(apiUrl(`/api/v1/config/${configType}`));if (res.ok) {@@ -51,7 +47,11 @@ export default function ConfigTab({} finally {setLoading(false);}- };+ }, [configType]);++ useEffect(() => {+ loadConfigs();+ }, [loadConfigs]);const setActive = async (configId: string) => {try {diff --git a/web/app/solver/page.tsx b/web/app/solver/page.tsxindex 8a9ddf29e..81993a7ed 100644--- a/web/app/solver/page.tsx+++ b/web/app/solver/page.tsx@@ -253,7 +253,8 @@ export default function SolverPage() {resolveArtifactUrl(url, msg.outputDir)}components={{- img: ({ node, src, ...props }) => (+ img: ({ node, src, alt, ...props }) => (+ // eslint-disable-next-line @next/next/no-img-element -- Dynamic images from markdown content<img{...props}src={@@ -262,6 +263,7 @@ export default function SolverPage() {msg.outputDir,) || undefined}+ alt={alt || "Solution image"}loading="lazy"className="max-w-full h-auto"/>@@ -323,7 +325,8 @@ export default function SolverPage() {resolveArtifactUrl(url, msg.outputDir)}components={{- img: ({ node, src, ...props }) => (+ img: ({ node, src, alt, ...props }) => (+ // eslint-disable-next-line @next/next/no-img-element -- Dynamic images from markdown content<img{...props}src={@@ -332,6 +335,7 @@ export default function SolverPage() {msg.outputDir,) || undefined}+ alt={alt || "Solution image"}loading="lazy"className="max-w-full h-auto"/>diff --git a/web/components/ActivityDetail.tsx b/web/components/ActivityDetail.tsxindex e50476745..054aa2563 100644--- a/web/components/ActivityDetail.tsx+++ b/web/components/ActivityDetail.tsx@@ -1,6 +1,6 @@"use client";-import { useState, useEffect } from "react";+import { useState, useEffect, useSyncExternalStore } from "react";import { createPortal } from "react-dom";import { X, FileText, HelpCircle, Search, Clock, Database } from "lucide-react";import ReactMarkdown from "react-markdown";@@ -10,6 +10,16 @@ import rehypeKatex from "rehype-katex";import "katex/dist/katex.min.css";import { processLatexContent } from "@/lib/latex";+// Hook to safely detect client-side rendering+const emptySubscribe = () => () => {};+function useIsClient() {+ return useSyncExternalStore(+ emptySubscribe,+ () => true,+ () => false+ );+}+interface ActivityDetailProps {activity: any;onClose: () => void;@@ -19,13 +29,7 @@ export default function ActivityDetail({activity,onClose,}: ActivityDetailProps) {- const [mounted, setMounted] = useState(false);-- // Ensure we're on the client before rendering portal- useEffect(() => {- setMounted(true);- return () => setMounted(false);- }, []);+ const mounted = useIsClient();// Handle escape key to close modaluseEffect(() => {diff --git a/web/components/CoMarkerEditor.tsx b/web/components/CoMarkerEditor.tsxindex ba4a342ec..8a819a623 100644--- a/web/components/CoMarkerEditor.tsx+++ b/web/components/CoMarkerEditor.tsx@@ -22,7 +22,7 @@ import {ListOrdered,Quote,Link,- Image,+ Image as ImageIcon,Table,Minus,Download,@@ -337,6 +337,7 @@ export default function CoWriterEditor({// When restoring, need to map edits back to original contentsetRawContent("");}+ // eslint-disable-next-line react-hooks/exhaustive-deps -- Only trigger on hideAiMarks toggle, not content changes}, [hideAiMarks]);// Merge edits with tags - smart AI mark protection@@ -1339,7 +1340,7 @@ export default function CoWriterEditor({title="Link"/><ToolbarButton- icon={<Image className="w-4 h-4" />}+ icon={<ImageIcon className="w-4 h-4" />}onClick={() => wrapSelection("")}title="Image"/>@@ -1470,7 +1471,7 @@ export default function CoWriterEditor({<div className="p-4 space-y-4">{/* Selected Text Preview */}<div className="text-xs text-slate-500 bg-slate-50 p-2 rounded-lg border border-slate-100 line-clamp-2 italic">- "{selection?.text}"+ "{selection?.text}"</div>{/* Instruction Input */}@@ -1830,7 +1831,7 @@ export default function CoWriterEditor({</span></div><div className="text-xs text-slate-600 truncate mb-1">- "{op.input?.original_text?.substring(0, 35)}..."+ "{op.input?.original_text?.substring(0, 35)}..."</div><div className="flex items-center gap-2 text-[10px] text-slate-400">{op.source && (diff --git a/web/components/CoWriterEditor.tsx b/web/components/CoWriterEditor.tsxindex e70b70a04..34ec3cb5c 100644--- a/web/components/CoWriterEditor.tsx+++ b/web/components/CoWriterEditor.tsx@@ -22,7 +22,7 @@ import {ListOrdered,Quote,Link,- Image,+ Image as ImageIcon,Table,Minus,Download,@@ -337,6 +337,7 @@ export default function CoWriterEditor({// When restoring, need to map edits back to original contentsetRawContent("");}+ // eslint-disable-next-line react-hooks/exhaustive-deps -- Only trigger on hideAiMarks toggle, not content changes}, [hideAiMarks]);// Merge edits with tags - smart AI mark protection@@ -1341,7 +1342,7 @@ export default function CoWriterEditor({title="Link"/><ToolbarButton- icon={<Image className="w-4 h-4" />}+ icon={<ImageIcon className="w-4 h-4" />}onClick={() => wrapSelection("")}title="Image"/>@@ -1472,7 +1473,7 @@ export default function CoWriterEditor({<div className="p-4 space-y-4">{/* Selected Text Preview */}<div className="text-xs text-slate-500 dark:text-slate-400 bg-slate-50 dark:bg-slate-700 p-2 rounded-lg border border-slate-100 dark:border-slate-600 line-clamp-2 italic">- "{selection?.text}"+ "{selection?.text}"</div>{/* Instruction Input */}@@ -1832,7 +1833,7 @@ export default function CoWriterEditor({</span></div><div className="text-xs text-slate-600 dark:text-slate-400 truncate mb-1">- "{op.input?.original_text?.substring(0, 35)}..."+ "{op.input?.original_text?.substring(0, 35)}..."</div><div className="flex items-center gap-2 text-[10px] text-slate-400 dark:text-slate-500">{op.source && (diff --git a/web/components/Sidebar.tsx b/web/components/Sidebar.tsxindex 087a7aaa4..faeebaf91 100644--- a/web/components/Sidebar.tsx+++ b/web/components/Sidebar.tsx@@ -1,6 +1,6 @@"use client";-import { useState, useRef, useEffect, useMemo } from "react";+import { useState, useRef, useEffect, useMemo, useCallback } from "react";import Link from "next/link";import Image from "next/image";import { usePathname } from "next/navigation";@@ -65,7 +65,7 @@ export default function Sidebar() {} = useGlobal();const lang = uiSettings.language;- const t = (key: string) => getTranslation(lang, key);+ const t = useCallback((key: string) => getTranslation(lang, key), [lang]);const [showTooltip, setShowTooltip] = useState<string | null>(null);@@ -82,19 +82,19 @@ export default function Sidebar() {null,);- // Build navigation items from saved order- const buildNavItems = (hrefs: string[]): NavItem[] => {- return hrefs- .filter((href) => ALL_NAV_ITEMS[href])- .map((href) => ({- name: t(ALL_NAV_ITEMS[href].nameKey),- href,- icon: ALL_NAV_ITEMS[href].icon,- }));- };-- const navGroups = useMemo(- () => [+ // Build navigation items from saved order - defined inside useMemo to properly capture dependencies+ const navGroups = useMemo(() => {+ const buildNavItems = (hrefs: string[]): NavItem[] => {+ return hrefs+ .filter((href) => ALL_NAV_ITEMS[href])+ .map((href) => ({+ name: t(ALL_NAV_ITEMS[href].nameKey),+ href,+ icon: ALL_NAV_ITEMS[href].icon,+ }));+ };++ return [{id: "start" as const,name: "WORKSPACE",@@ -105,9 +105,8 @@ export default function Sidebar() {name: t("Learn") + " & " + t("Research"),items: buildNavItems(sidebarNavOrder.learnResearch),},- ],- [sidebarNavOrder, lang],- );+ ];+ }, [sidebarNavOrder, t]);// Handle description editconst handleDescriptionEdit = () => {diff --git a/web/components/research/ResearchDashboard.tsx b/web/components/research/ResearchDashboard.tsxindex a3d24a1bc..65a09a541 100644--- a/web/components/research/ResearchDashboard.tsx+++ b/web/components/research/ResearchDashboard.tsx@@ -1,4 +1,4 @@-import React, { useState, useEffect } from "react";+import React, { useState, useEffect, useRef, useMemo, startTransition } from "react";import { ResearchState } from "../../types/research";import { TaskGrid } from "./TaskGrid";import { ActiveTaskDetail } from "./ActiveTaskDetail";@@ -31,6 +31,21 @@ import {type ProcessTab = "planning" | "researching" | "reporting";+// Steps configuration - moved outside component to avoid recreation+const steps: { id: ProcessTab; label: string; icon: React.ElementType }[] = [+ { id: "planning", label: "Planning", icon: GitBranch },+ { id: "researching", label: "Researching", icon: Zap },+ { id: "reporting", label: "Reporting", icon: PenTool },+];++const stageOrder: Record<string, number> = {+ idle: -1,+ planning: 0,+ researching: 1,+ reporting: 2,+ completed: 3,+};+interface ResearchDashboardProps {state: ResearchState;selectedTaskId: string | null;@@ -51,23 +66,35 @@ export const ResearchDashboard: React.FC<ResearchDashboardProps> = ({isExportingPdf = false,}) => {const { global, tasks, activeTaskIds, planning, reporting } = state;- const [activeView, setActiveView] = useState<"process" | "report">("process");- const [activeProcessTab, setActiveProcessTab] =- useState<ProcessTab>("planning");-- const steps: { id: ProcessTab; label: string; icon: React.ElementType }[] = [- { id: "planning", label: "Planning", icon: GitBranch },- { id: "researching", label: "Researching", icon: Zap },- { id: "reporting", label: "Reporting", icon: PenTool },- ];-- const stageOrder: Record<string, number> = {- idle: -1,- planning: 0,- researching: 1,- reporting: 2,- completed: 3,++ // Track previous stage to detect changes and reset user selection+ const [prevStage, setPrevStage] = useState(global.stage);++ // User can override the auto-selected tab+ const [userSelectedTab, setUserSelectedTab] = useState<ProcessTab | null>(null);++ // Compute derived tab based on current stage+ const derivedProcessTab: ProcessTab =+ global.stage === "planning" || global.stage === "researching" || global.stage === "reporting"+ ? global.stage+ : "reporting";++ // Detect stage changes and reset user selection+ if (prevStage !== global.stage) {+ setPrevStage(global.stage);+ setUserSelectedTab(null);+ }++ // Active tab is user selection or derived+ const activeProcessTab = userSelectedTab ?? derivedProcessTab;++ // Handler for user tab selection+ const setActiveProcessTab = (tab: ProcessTab) => {+ setUserSelectedTab(tab);};++ // View state+ const [activeView, setActiveView] = useState<"process" | "report">("process");const currentStageIndex = stageOrder[global.stage] ?? -1;const isCompleted = global.stage === "completed";@@ -83,18 +110,6 @@ export const ResearchDashboard: React.FC<ResearchDashboardProps> = ({return global.stage === tabId;};- // Auto-switch to current stage tab when stage changes- useEffect(() => {- if (global.stage === "planning") {- setActiveProcessTab("planning");- } else if (global.stage === "researching") {- setActiveProcessTab("researching");- } else if (global.stage === "reporting") {- setActiveProcessTab("reporting");- }- // When completed, stay on current tab (user can browse freely)- }, [global.stage]);-// Auto-switch to report view when research completes and report is availableuseEffect(() => {if (@@ -103,21 +118,25 @@ export const ResearchDashboard: React.FC<ResearchDashboardProps> = ({activeView === "process") {const timer = setTimeout(() => {- setActiveView("report");+ startTransition(() => {+ setActiveView("report");+ });}, 1500);return () => clearTimeout(timer);}- }, [global.stage, reporting.generatedReport]);+ }, [global.stage, reporting.generatedReport, activeView]);- // Reset to process view when a new research starts+ // Reset to process view when a new research startsuseEffect(() => {- if (global.stage === "planning") {- setActiveView("process");+ if (global.stage === "planning" && prevStageRef.current !== "planning") {+ startTransition(() => {+ setActiveView("process");+ });}}, [global.stage]);- // Clickable Step Tabs- const StepTabs = () => (+ // Clickable Step Tabs - rendered as JSX variable instead of component function+ const stepTabsContent = (<div className="flex items-center gap-1 bg-slate-100/80 dark:bg-slate-800/80 backdrop-blur-sm p-1 rounded-xl border border-slate-200/50 dark:border-slate-700/50 shadow-sm">{steps.map((step, idx) => {const available = isTabAvailable(step.id);@@ -166,350 +185,338 @@ export const ResearchDashboard: React.FC<ResearchDashboardProps> = ({</div>);- // Planning Content- const PlanningContent = () => {- const isActive = global.stage === "planning";-- return (- <div className="flex-1 flex items-center justify-center">+ // Planning Content - rendered as JSX variable+ const isPlanningActive = global.stage === "planning";+ const planningContent = (+ <div className="flex-1 flex items-center justify-center">+ <div+ className={`bg-white dark:bg-slate-800 rounded-xl border shadow-sm p-8 flex flex-col items-center justify-center text-center max-w-2xl w-full ${+ isPlanningActive+ ? "border-blue-200 dark:border-blue-800"+ : "border-slate-200 dark:border-slate-700"+ }`}+ ><div- className={`bg-white dark:bg-slate-800 rounded-xl border shadow-sm p-8 flex flex-col items-center justify-center text-center max-w-2xl w-full ${- isActive- ? "border-blue-200 dark:border-blue-800"- : "border-slate-200 dark:border-slate-700"+ className={`w-16 h-16 rounded-full flex items-center justify-center mb-4 ${+ isPlanningActive+ ? "bg-blue-50 dark:bg-blue-900/40"+ : "bg-slate-50 dark:bg-slate-700"}`}>- <div- className={`w-16 h-16 rounded-full flex items-center justify-center mb-4 ${- isActive- ? "bg-blue-50 dark:bg-blue-900/40"- : "bg-slate-50 dark:bg-slate-700"- }`}- >- <GitBranch- className={`w-8 h-8 ${isActive ? "text-blue-500 dark:text-blue-400" : "text-slate-400 dark:text-slate-500"}`}- />- </div>-- {isActive && (- <Loader2 className="w-6 h-6 text-blue-500 dark:text-blue-400 animate-spin mb-4" />- )}- {!isActive && currentStageIndex > 0 && (- <CheckCircle2 className="w-6 h-6 text-emerald-500 dark:text-emerald-400 mb-4" />- )}-- <h3 className="text-lg font-semibold text-slate-800 dark:text-slate-100 mb-2">- {isActive ? "Planning Research Strategy" : "Research Plan"}- </h3>-- {isActive && (- <p className="text-slate-500 dark:text-slate-400 text-sm mb-4">- {planning.progress || "Initializing..."}- </p>- )}+ <GitBranch+ className={`w-8 h-8 ${isPlanningActive ? "text-blue-500 dark:text-blue-400" : "text-slate-400 dark:text-slate-500"}`}+ />+ </div>- {/* Topic Info */}- {(planning.originalTopic || planning.optimizedTopic) && (- <div className="w-full mt-4 bg-slate-50 dark:bg-slate-700 rounded-lg p-4 border border-slate-100 dark:border-slate-600 text-left">- {planning.originalTopic && (- <div className="mb-3">+ {isPlanningActive && (+ <Loader2 className="w-6 h-6 text-blue-500 dark:text-blue-400 animate-spin mb-4" />+ )}+ {!isPlanningActive && currentStageIndex > 0 && (+ <CheckCircle2 className="w-6 h-6 text-emerald-500 dark:text-emerald-400 mb-4" />+ )}++ <h3 className="text-lg font-semibold text-slate-800 dark:text-slate-100 mb-2">+ {isPlanningActive ? "Planning Research Strategy" : "Research Plan"}+ </h3>++ {isPlanningActive && (+ <p className="text-slate-500 dark:text-slate-400 text-sm mb-4">+ {planning.progress || "Initializing..."}+ </p>+ )}++ {/* Topic Info */}+ {(planning.originalTopic || planning.optimizedTopic) && (+ <div className="w-full mt-4 bg-slate-50 dark:bg-slate-700 rounded-lg p-4 border border-slate-100 dark:border-slate-600 text-left">+ {planning.originalTopic && (+ <div className="mb-3">+ <p className="text-xs font-semibold text-slate-400 dark:text-slate-500 uppercase tracking-wider mb-1">+ Original Topic+ </p>+ <p className="text-sm text-slate-700 dark:text-slate-200">+ {planning.originalTopic}+ </p>+ </div>+ )}+ {planning.optimizedTopic &&+ planning.optimizedTopic !== planning.originalTopic && (+ <div><p className="text-xs font-semibold text-slate-400 dark:text-slate-500 uppercase tracking-wider mb-1">- Original Topic+ Optimized Topic</p><p className="text-sm text-slate-700 dark:text-slate-200">- {planning.originalTopic}+ {planning.optimizedTopic}</p></div>)}- {planning.optimizedTopic &&- planning.optimizedTopic !== planning.originalTopic && (- <div>- <p className="text-xs font-semibold text-slate-400 dark:text-slate-500 uppercase tracking-wider mb-1">- Optimized Topic- </p>- <p className="text-sm text-slate-700 dark:text-slate-200">- {planning.optimizedTopic}- </p>- </div>- )}- </div>- )}-- {/* Sub Topics */}- {planning.subTopics.length > 0 && (- <div className="w-full mt-4">- <p className="text-xs font-semibold text-slate-400 dark:text-slate-500 uppercase tracking-wider mb-3 text-left">- Research Sub-topics ({planning.subTopics.length})- </p>- <div className="flex flex-wrap gap-2">- {planning.subTopics.map((topic, i) => (- <span- key={i}- className="px-3 py-1.5 bg-blue-50 dark:bg-blue-900/40 text-blue-700 dark:text-blue-300 text-xs rounded-lg border border-blue-100 dark:border-blue-800 font-medium"- >- {topic.sub_topic}- </span>- ))}- </div>- </div>- )}- </div>- </div>- );- };-- // Researching Content- const ResearchingContent = () => {- const isActive = global.stage === "researching";- const hasContent = Object.keys(tasks).length > 0;-- if (!hasContent) {- return (- <div className="flex-1 flex items-center justify-center">- <div className="text-center text-slate-400 dark:text-slate-500">- <Zap className="w-12 h-12 mx-auto mb-3 opacity-30" />- <p>No research data yet</p></div>- </div>- );- }+ )}- return (- <div className="flex-1 min-h-0 flex gap-6">- {/* Left: Task Grid - flex-[3] means 3 parts of available space */}- <div className="flex-[3] min-w-[200px] flex flex-col gap-4 overflow-hidden">- <div className="flex items-center justify-between shrink-0">- <h3 className="font-bold text-slate-700 dark:text-slate-200 flex items-center gap-2">- <Zap className="w-4 h-4 text-amber-500 dark:text-amber-400" />- Research Tasks- {!isActive && (- <span className="text-xs font-normal text-slate-400 dark:text-slate-500 ml-2">- (History)- </span>- )}- </h3>- <div className="flex items-center gap-3 text-xs text-slate-500 dark:text-slate-400">- {isActive && (- <span className="text-indigo-600 dark:text-indigo-400 font-medium">- {state.activeTaskIds.length} active+ {/* Sub Topics */}+ {planning.subTopics.length > 0 && (+ <div className="w-full mt-4">+ <p className="text-xs font-semibold text-slate-400 dark:text-slate-500 uppercase tracking-wider mb-3 text-left">+ Research Sub-topics ({planning.subTopics.length})+ </p>+ <div className="flex flex-wrap gap-2">+ {planning.subTopics.map((topic, i) => (+ <span+ key={i}+ className="px-3 py-1.5 bg-blue-50 dark:bg-blue-900/40 text-blue-700 dark:text-blue-300 text-xs rounded-lg border border-blue-100 dark:border-blue-800 font-medium"+ >+ {topic.sub_topic}</span>- )}- <span>- {global.completedBlocks} / {global.totalBlocks} completed- </span>+ ))}</div></div>- <div className="flex-1 overflow-y-auto pr-2">- <TaskGrid- tasks={tasks}- activeTaskIds={isActive ? activeTaskIds : []}- selectedTaskId={selectedTaskId}- onTaskSelect={onTaskSelect}- />- </div>- </div>+ )}+ </div>+ </div>+ );- {/* Right: Active Details - flex-[2] means 2 parts of available space */}- {/* Both sides shrink proportionally (3:2 ratio) when space is limited */}- <div className="flex-[2] min-w-[280px] flex flex-col gap-4 overflow-hidden">- <h3 className="font-bold text-slate-700 dark:text-slate-200 flex items-center gap-2 shrink-0">- <Activity className="w-4 h-4 text-indigo-500 dark:text-indigo-400" />- {isActive ? "Live Execution" : "Execution History"}+ // Researching Content - rendered as JSX variable+ const isResearchingActive = global.stage === "researching";+ const hasResearchContent = Object.keys(tasks).length > 0;+ const researchingContent = !hasResearchContent ? (+ <div className="flex-1 flex items-center justify-center">+ <div className="text-center text-slate-400 dark:text-slate-500">+ <Zap className="w-12 h-12 mx-auto mb-3 opacity-30" />+ <p>No research data yet</p>+ </div>+ </div>+ ) : (+ <div className="flex-1 min-h-0 flex gap-6">+ {/* Left: Task Grid - flex-[3] means 3 parts of available space */}+ <div className="flex-[3] min-w-[200px] flex flex-col gap-4 overflow-hidden">+ <div className="flex items-center justify-between shrink-0">+ <h3 className="font-bold text-slate-700 dark:text-slate-200 flex items-center gap-2">+ <Zap className="w-4 h-4 text-amber-500 dark:text-amber-400" />+ Research Tasks+ {!isResearchingActive && (+ <span className="text-xs font-normal text-slate-400 dark:text-slate-500 ml-2">+ (History)+ </span>+ )}</h3>- <div className="flex-1 min-h-0 overflow-hidden">- <ActiveTaskDetail- task={selectedTaskId ? tasks[selectedTaskId] : null}- />+ <div className="flex items-center gap-3 text-xs text-slate-500 dark:text-slate-400">+ {isResearchingActive && (+ <span className="text-indigo-600 dark:text-indigo-400 font-medium">+ {state.activeTaskIds.length} active+ </span>+ )}+ <span>+ {global.completedBlocks} / {global.totalBlocks} completed+ </span></div></div>+ <div className="flex-1 overflow-y-auto pr-2">+ <TaskGrid+ tasks={tasks}+ activeTaskIds={isResearchingActive ? activeTaskIds : []}+ selectedTaskId={selectedTaskId}+ onTaskSelect={onTaskSelect}+ />+ </div></div>- );- };- // Reporting Content- const ReportingContent = () => {- const isActive = global.stage === "reporting";+ {/* Right: Active Details - flex-[2] means 2 parts of available space */}+ {/* Both sides shrink proportionally (3:2 ratio) when space is limited */}+ <div className="flex-[2] min-w-[280px] flex flex-col gap-4 overflow-hidden">+ <h3 className="font-bold text-slate-700 dark:text-slate-200 flex items-center gap-2 shrink-0">+ <Activity className="w-4 h-4 text-indigo-500 dark:text-indigo-400" />+ {isResearchingActive ? "Live Execution" : "Execution History"}+ </h3>+ <div className="flex-1 min-h-0 overflow-hidden">+ <ActiveTaskDetail+ task={selectedTaskId ? tasks[selectedTaskId] : null}+ />+ </div>+ </div>+ </div>+ );- return (- <div className="flex-1 flex items-center justify-center">+ // Reporting Content+ // Reporting Content - rendered as JSX variable+ const isReportingActive = global.stage === "reporting";+ const reportingContent = (+ <div className="flex-1 flex items-center justify-center">+ <div+ className={`bg-white dark:bg-slate-800 rounded-xl border shadow-sm p-8 flex flex-col items-center justify-center text-center max-w-lg w-full ${+ isReportingActive+ ? "border-purple-200 dark:border-purple-800"+ : isCompleted+ ? "border-emerald-200 dark:border-emerald-800"+ : "border-slate-200 dark:border-slate-700"+ }`}+ ><div- className={`bg-white dark:bg-slate-800 rounded-xl border shadow-sm p-8 flex flex-col items-center justify-center text-center max-w-lg w-full ${- isActive- ? "border-purple-200 dark:border-purple-800"+ className={`w-16 h-16 rounded-full flex items-center justify-center mb-4 ${+ isReportingActive+ ? "bg-purple-50 dark:bg-purple-900/40": isCompleted- ? "border-emerald-200 dark:border-emerald-800"- : "border-slate-200 dark:border-slate-700"+ ? "bg-emerald-50 dark:bg-emerald-900/40"+ : "bg-slate-50 dark:bg-slate-700"}`}>- <div- className={`w-16 h-16 rounded-full flex items-center justify-center mb-4 ${- isActive- ? "bg-purple-50 dark:bg-purple-900/40"- : isCompleted- ? "bg-emerald-50 dark:bg-emerald-900/40"- : "bg-slate-50 dark:bg-slate-700"- }`}- >- {isCompleted ? (- <Sparkles className="w-8 h-8 text-emerald-500 dark:text-emerald-400" />- ) : (- <PenTool- className={`w-8 h-8 ${isActive ? "text-purple-500 dark:text-purple-400" : "text-slate-400 dark:text-slate-500"}`}- />- )}- </div>-- {isActive && (- <Loader2 className="w-6 h-6 text-purple-500 dark:text-purple-400 animate-spin mb-4" />- )}- {isCompleted && (- <CheckCircle2 className="w-6 h-6 text-emerald-500 dark:text-emerald-400 mb-4" />- )}-- <h3 className="text-lg font-semibold text-slate-800 dark:text-slate-100 mb-2">- {isCompleted- ? "Report Generated!"- : isActive- ? "Generating Report"- : "Report Generation"}- </h3>-- {/* Current Section Being Written */}- {isActive && reporting.currentSection && (- <div className="bg-purple-50 dark:bg-purple-900/30 border border-purple-100 dark:border-purple-800 rounded-lg px-4 py-2 mb-4 w-full">- <p className="text-xs text-purple-600 dark:text-purple-400 font-medium uppercase tracking-wider mb-1">- Currently Writing- </p>- <p className="text-purple-800 dark:text-purple-200 font-semibold">- {reporting.currentSection}- </p>- {reporting.totalSections &&- reporting.sectionIndex !== undefined && (- <p className="text-xs text-purple-500 dark:text-purple-400 mt-1">- Section {reporting.sectionIndex + 1} of{" "}- {reporting.totalSections}- </p>- )}- </div>+ {isCompleted ? (+ <Sparkles className="w-8 h-8 text-emerald-500 dark:text-emerald-400" />+ ) : (+ <PenTool+ className={`w-8 h-8 ${isReportingActive ? "text-purple-500 dark:text-purple-400" : "text-slate-400 dark:text-slate-500"}`}+ />)}+ </div>- {/* Progress Bar */}- {isActive &&- reporting.totalSections &&- reporting.sectionIndex !== undefined && (- <div className="w-full mb-4">- <div className="h-2 bg-purple-100 dark:bg-purple-900/40 rounded-full overflow-hidden">- <div- className="h-full bg-purple-500 rounded-full transition-all duration-500"- style={{- width: `${((reporting.sectionIndex + 1) / reporting.totalSections) * 100}%`,- }}- />- </div>- <p className="text-xs text-slate-400 dark:text-slate-500 mt-1">- {Math.round(- ((reporting.sectionIndex + 1) / reporting.totalSections) *- 100,- )}- % complete- </p>- </div>- )}-- {isActive && (- <p className="text-slate-500 dark:text-slate-400 text-sm mb-4">- {reporting.progress || "Processing research findings..."}+ {isReportingActive && (+ <Loader2 className="w-6 h-6 text-purple-500 dark:text-purple-400 animate-spin mb-4" />+ )}+ {isCompleted && (+ <CheckCircle2 className="w-6 h-6 text-emerald-500 dark:text-emerald-400 mb-4" />+ )}++ <h3 className="text-lg font-semibold text-slate-800 dark:text-slate-100 mb-2">+ {isCompleted+ ? "Report Generated!"+ : isReportingActive+ ? "Generating Report"+ : "Report Generation"}+ </h3>++ {/* Current Section Being Written */}+ {isReportingActive && reporting.currentSection && (+ <div className="bg-purple-50 dark:bg-purple-900/30 border border-purple-100 dark:border-purple-800 rounded-lg px-4 py-2 mb-4 w-full">+ <p className="text-xs text-purple-600 dark:text-purple-400 font-medium uppercase tracking-wider mb-1">+ Currently Writing</p>- )}-- {/* Stats */}- <div className="flex items-center gap-6 text-sm text-slate-600 dark:text-slate-300 mt-2">- {global.totalBlocks > 0 && (- <div className="flex items-center gap-1.5">- <ListTree- className={`w-4 h-4 ${isCompleted ? "text-emerald-500 dark:text-emerald-400" : "text-slate-400 dark:text-slate-500"}`}- />- <span>{global.totalBlocks} topics</span>- </div>- )}- {reporting.wordCount && (- <div className="flex items-center gap-1.5">- <FileText- className={`w-4 h-4 ${isCompleted ? "text-emerald-500 dark:text-emerald-400" : "text-slate-400 dark:text-slate-500"}`}+ <p className="text-purple-800 dark:text-purple-200 font-semibold">+ {reporting.currentSection}+ </p>+ {reporting.totalSections &&+ reporting.sectionIndex !== undefined && (+ <p className="text-xs text-purple-500 dark:text-purple-400 mt-1">+ Section {reporting.sectionIndex + 1} of{" "}+ {reporting.totalSections}+ </p>+ )}+ </div>+ )}++ {/* Progress Bar */}+ {isReportingActive &&+ reporting.totalSections &&+ reporting.sectionIndex !== undefined && (+ <div className="w-full mb-4">+ <div className="h-2 bg-purple-100 dark:bg-purple-900/40 rounded-full overflow-hidden">+ <div+ className="h-full bg-purple-500 rounded-full transition-all duration-500"+ style={{+ width: `${((reporting.sectionIndex + 1) / reporting.totalSections) * 100}%`,+ }}/>- <span>{reporting.wordCount.toLocaleString()} words</span></div>- )}- {reporting.outline && reporting.outline.sections.length > 0 && (- <div className="flex items-center gap-1.5">- <FileText className="w-4 h-4 text-slate-400 dark:text-slate-500" />- <span>{reporting.outline.sections.length} sections</span>- </div>- )}- </div>-- {/* Outline Preview */}- {reporting.outline && reporting.outline.sections.length > 0 && (- <div className="mt-6 w-full text-left bg-slate-50 dark:bg-slate-700 rounded-lg p-4 border border-slate-100 dark:border-slate-600 max-h-[200px] overflow-y-auto">- <p className="text-xs font-semibold text-slate-500 dark:text-slate-400 uppercase tracking-wider mb-3">- Report Outline+ <p className="text-xs text-slate-400 dark:text-slate-500 mt-1">+ {Math.round(+ ((reporting.sectionIndex + 1) / reporting.totalSections) *+ 100,+ )}+ % complete</p>- <ul className="space-y-2">- {reporting.outline.sections.map((section, i) => (- <li- key={i}- className="flex items-center gap-2 text-sm text-slate-600 dark:text-slate-300"- >- <span- className={`w-5 h-5 rounded text-xs flex items-center justify-center font-medium shrink-0 ${- isActive &&- reporting.sectionIndex !== undefined &&- i + 1 === reporting.sectionIndex- ? "bg-purple-500 text-white animate-pulse"- : isCompleted ||- (reporting.sectionIndex !== undefined &&- i + 1 < reporting.sectionIndex)- ? "bg-emerald-100 dark:bg-emerald-900/50 text-emerald-600 dark:text-emerald-400"- : "bg-purple-100 dark:bg-purple-900/50 text-purple-600 dark:text-purple-400"- }`}- >- {isCompleted ||- (reporting.sectionIndex !== undefined &&- i + 1 < reporting.sectionIndex)- ? "✓"- : i + 1}- </span>- <span- className={`line-clamp-1 ${- isActive &&- reporting.sectionIndex !== undefined &&- i + 1 === reporting.sectionIndex- ? "text-purple-700 dark:text-purple-300 font-medium"- : ""- }`}- >- {section.title.replace(/^##\s*\d*\.?\s*/, "")}- </span>- </li>- ))}- </ul></div>)}- {/* View Report Button (when completed) */}- {isCompleted && reporting.generatedReport && (- <button- onClick={() => setActiveView("report")}- className="mt-6 flex items-center justify-center gap-2 w-full py-3 px-4 bg-indigo-600 hover:bg-indigo-700 text-white rounded-xl font-medium transition-colors shadow-sm"- >- <FileText className="w-4 h-4" />- View Full Report- </button>+ {isReportingActive && (+ <p className="text-slate-500 dark:text-slate-400 text-sm mb-4">+ {reporting.progress || "Processing research findings..."}+ </p>+ )}++ {/* Stats */}+ <div className="flex items-center gap-6 text-sm text-slate-600 dark:text-slate-300 mt-2">+ {global.totalBlocks > 0 && (+ <div className="flex items-center gap-1.5">+ <ListTree+ className={`w-4 h-4 ${isCompleted ? "text-emerald-500 dark:text-emerald-400" : "text-slate-400 dark:text-slate-500"}`}+ />+ <span>{global.totalBlocks} topics</span>+ </div>+ )}+ {reporting.wordCount && (+ <div className="flex items-center gap-1.5">+ <FileText+ className={`w-4 h-4 ${isCompleted ? "text-emerald-500 dark:text-emerald-400" : "text-slate-400 dark:text-slate-500"}`}+ />+ <span>{reporting.wordCount.toLocaleString()} words</span>+ </div>+ )}+ {reporting.outline && reporting.outline.sections.length > 0 && (+ <div className="flex items-center gap-1.5">+ <FileText className="w-4 h-4 text-slate-400 dark:text-slate-500" />+ <span>{reporting.outline.sections.length} sections</span>+ </div>)}</div>++ {/* Outline Preview */}+ {reporting.outline && reporting.outline.sections.length > 0 && (+ <div className="mt-6 w-full text-left bg-slate-50 dark:bg-slate-700 rounded-lg p-4 border border-slate-100 dark:border-slate-600 max-h-[200px] overflow-y-auto">+ <p className="text-xs font-semibold text-slate-500 dark:text-slate-400 uppercase tracking-wider mb-3">+ Report Outline+ </p>+ <ul className="space-y-2">+ {reporting.outline.sections.map((section, i) => (+ <li+ key={i}+ className="flex items-center gap-2 text-sm text-slate-600 dark:text-slate-300"+ >+ <span+ className={`w-5 h-5 rounded text-xs flex items-center justify-center font-medium shrink-0 ${+ isReportingActive &&+ reporting.sectionIndex !== undefined &&+ i + 1 === reporting.sectionIndex+ ? "bg-purple-500 text-white animate-pulse"+ : isCompleted ||+ (reporting.sectionIndex !== undefined &&+ i + 1 < reporting.sectionIndex)+ ? "bg-emerald-100 dark:bg-emerald-900/50 text-emerald-600 dark:text-emerald-400"+ : "bg-purple-100 dark:bg-purple-900/50 text-purple-600 dark:text-purple-400"+ }`}+ >+ {isCompleted ||+ (reporting.sectionIndex !== undefined &&+ i + 1 < reporting.sectionIndex)+ ? "✓"+ : i + 1}+ </span>+ <span+ className={`line-clamp-1 ${+ isReportingActive &&+ reporting.sectionIndex !== undefined &&+ i + 1 === reporting.sectionIndex+ ? "text-purple-700 dark:text-purple-300 font-medium"+ : ""+ }`}+ >+ {section.title.replace(/^##\s*\d*\.?\s*/, "")}+ </span>+ </li>+ ))}+ </ul>+ </div>+ )}++ {/* View Report Button (when completed) */}+ {isCompleted && reporting.generatedReport && (+ <button+ onClick={() => setActiveView("report")}+ className="mt-6 flex items-center justify-center gap-2 w-full py-3 px-4 bg-indigo-600 hover:bg-indigo-700 text-white rounded-xl font-medium transition-colors shadow-sm"+ >+ <FileText className="w-4 h-4" />+ View Full Report+ </button>+ )}</div>- );- };+ </div>+ );return (<div className="flex flex-col h-full bg-slate-50/50 dark:bg-slate-900/50">@@ -622,14 +629,14 @@ export const ResearchDashboard: React.FC<ResearchDashboardProps> = ({<>{/* Step Tabs */}<div className="px-6 pt-4 pb-2 flex justify-center shrink-0">- <StepTabs />+ {stepTabsContent}</div>{/* Tab Content */}<div className="flex-1 overflow-hidden p-6 flex flex-col">- {activeProcessTab === "planning" && <PlanningContent />}- {activeProcessTab === "researching" && <ResearchingContent />}- {activeProcessTab === "reporting" && <ReportingContent />}+ {activeProcessTab === "planning" && planningContent}+ {activeProcessTab === "researching" && researchingContent}+ {activeProcessTab === "reporting" && reportingContent}</div></>)}diff --git a/web/context/settings/SidebarContext.tsx b/web/context/settings/SidebarContext.tsxindex aabe5e230..9c1b61d6a 100644--- a/web/context/settings/SidebarContext.tsx+++ b/web/context/settings/SidebarContext.tsx@@ -17,6 +17,25 @@ import {DEFAULT_NAV_ORDER,} from "@/types/sidebar";+// Helper to get initial sidebar width from localStorage+function getInitialSidebarWidth(): number {+ if (typeof window === "undefined") return SIDEBAR_DEFAULT_WIDTH;+ const storedWidth = localStorage.getItem("sidebarWidth");+ if (storedWidth) {+ const width = parseInt(storedWidth, 10);+ if (!isNaN(width) && width >= SIDEBAR_MIN_WIDTH && width <= SIDEBAR_MAX_WIDTH) {+ return width;+ }+ }+ return SIDEBAR_DEFAULT_WIDTH;+}++// Helper to get initial collapsed state from localStorage+function getInitialCollapsed(): boolean {+ if (typeof window === "undefined") return false;+ return localStorage.getItem("sidebarCollapsed") === "true";+}+// Context typeinterface SidebarContextType {// Sidebar dimensions@@ -35,11 +54,9 @@ interface SidebarContextType {const SidebarContext = createContext<SidebarContextType | undefined>(undefined);export function SidebarProvider({ children }: { children: React.ReactNode }) {- // Sidebar dimensions state- const [sidebarWidth, setSidebarWidthState] = useState<number>(- SIDEBAR_DEFAULT_WIDTH,- );- const [sidebarCollapsed, setSidebarCollapsedState] = useState<boolean>(false);+ // Sidebar dimensions state - use lazy initialization+ const [sidebarWidth, setSidebarWidthState] = useState<number>(getInitialSidebarWidth);+ const [sidebarCollapsed, setSidebarCollapsedState] = useState<boolean>(getInitialCollapsed);// Sidebar customization stateconst [sidebarDescription, setSidebarDescriptionState] = useState<string>(@@ -48,29 +65,6 @@ export function SidebarProvider({ children }: { children: React.ReactNode }) {const [sidebarNavOrder, setSidebarNavOrderState] =useState<SidebarNavOrder>(DEFAULT_NAV_ORDER);- // Initialize sidebar state from localStorage- useEffect(() => {- if (typeof window !== "undefined") {- const storedWidth = localStorage.getItem("sidebarWidth");- const storedCollapsed = localStorage.getItem("sidebarCollapsed");-- if (storedWidth) {- const width = parseInt(storedWidth, 10);- if (- !isNaN(width) &&- width >= SIDEBAR_MIN_WIDTH &&- width <= SIDEBAR_MAX_WIDTH- ) {- setSidebarWidthState(width);- }- }-- if (storedCollapsed) {- setSidebarCollapsedState(storedCollapsed === "true");- }- }- }, []);-// Initialize sidebar customization from backend APIuseEffect(() => {const loadSidebarSettings = async () => {diff --git a/web/context/settings/UISettingsContext.tsx b/web/context/settings/UISettingsContext.tsxindex 1e4d5809d..9dd44aade 100644--- a/web/context/settings/UISettingsContext.tsx+++ b/web/context/settings/UISettingsContext.tsx@@ -6,6 +6,8 @@ import React, {useState,useEffect,useCallback,+ useRef,+ startTransition,} from "react";import { apiUrl } from "@/lib/api";import { initializeTheme, setTheme, getStoredTheme } from "@/lib/theme";@@ -14,6 +16,17 @@ import { UISettings, Theme, Language } from "@/types/common";// Language storage keyconst LANGUAGE_STORAGE_KEY = "deeptutor-language";+// Helper to get initial settings+function getInitialSettings(): UISettings {+ if (typeof window === "undefined") {+ return { theme: "light", language: "en" };+ }+ const initialTheme = initializeTheme();+ const storedLanguage =+ (localStorage.getItem(LANGUAGE_STORAGE_KEY) as Language) || "en";+ return { theme: initialTheme, language: storedLanguage };+}+// Context typeinterface UISettingsContextType {uiSettings: UISettings;@@ -31,11 +44,8 @@ export function UISettingsProvider({}: {children: React.ReactNode;}) {- const [uiSettings, setUiSettings] = useState<UISettings>({- theme: "light",- language: "en",- });- const [isInitialized, setIsInitialized] = useState(false);+ const [uiSettings, setUiSettings] = useState<UISettings>(getInitialSettings);+ const isInitializedRef = useRef(false);const refreshSettings = useCallback(async () => {// Try to load from backend API first, fallback to localStorage@@ -45,9 +55,11 @@ export function UISettingsProvider({const data = await res.json();const serverTheme = data.ui?.theme || "light";const serverLanguage = data.ui?.language || "en";- setUiSettings({- theme: serverTheme,- language: serverLanguage,+ startTransition(() => {+ setUiSettings({+ theme: serverTheme,+ language: serverLanguage,+ });});setTheme(serverTheme);// Sync to localStorage as cache@@ -71,9 +83,11 @@ export function UISettingsProvider({: "en";const themeToUse = storedTheme || "light";- setUiSettings({- theme: themeToUse,- language: storedLanguage,+ startTransition(() => {+ setUiSettings({+ theme: themeToUse,+ language: storedLanguage,+ });});setTheme(themeToUse);}, []);@@ -115,25 +129,12 @@ export function UISettingsProvider({}, []);useEffect(() => {- // Initialize settings on first render- if (!isInitialized) {- // First apply localStorage theme immediately to avoid flash- const initialTheme = initializeTheme();- const storedLanguage =- typeof window !== "undefined"- ? (localStorage.getItem(LANGUAGE_STORAGE_KEY) as Language) || "en"- : "en";-- setUiSettings({- theme: initialTheme,- language: storedLanguage,- });- setIsInitialized(true);-- // Then async load from server (which may override)+ // Async load settings from server on first render (which may override localStorage)+ if (!isInitializedRef.current) {+ isInitializedRef.current = true;refreshSettings();}- }, [isInitialized, refreshSettings]);+ }, [refreshSettings]);return (<UISettingsContext.Providerdiff --git a/web/hooks/useTheme.ts b/web/hooks/useTheme.tsindex a6a893101..e6abb1e84 100644--- a/web/hooks/useTheme.ts+++ b/web/hooks/useTheme.ts@@ -1,7 +1,7 @@/*** useTheme hook for managing theme throughout the application*/-import { useEffect, useState } from "react";+import { useState, useSyncExternalStore } from "react";import {setTheme,getStoredTheme,@@ -9,16 +9,26 @@ import {type Theme,} from "@/lib/theme";-export function useTheme() {- const [theme, setThemeState] = useState<Theme | null>(null);- const [isLoaded, setIsLoaded] = useState(false);+// Use useSyncExternalStore for safe client-side initialization+const emptySubscribe = () => () => {};+function useIsClient() {+ return useSyncExternalStore(+ emptySubscribe,+ () => true,+ () => false+ );+}- useEffect(() => {- // Initialize theme from localStorage- const initialTheme = initializeTheme();- setThemeState(initialTheme);- setIsLoaded(true);- }, []);+export function useTheme() {+ const isClient = useIsClient();+ const [theme, setThemeState] = useState<Theme>(() => {+ // Lazy initialization - safe for SSR+ if (typeof window !== "undefined") {+ return initializeTheme();+ }+ return "light";+ });+ const isLoaded = isClient;const updateTheme = (newTheme: Theme) => {setTheme(newTheme);