11import { MonitorIcon , MoonIcon , SunIcon } from "lucide-react" ;
2- import { useCallback , useEffect , useState } from "react" ;
2+ import { useCallback , useEffect , useMemo , useState } from "react" ;
33import { isElectron } from "../env" ;
44import { useTheme } from "../hooks/useTheme" ;
55import { DEFAULT_MODEL } from "../model-logic" ;
6+ import { derivePendingApprovals } from "../session-logic" ;
67import { useStore } from "../store" ;
7- import { DEFAULT_THREAD_TERMINAL_HEIGHT , type Project } from "../types" ;
8+ import { DEFAULT_THREAD_TERMINAL_HEIGHT , type Project , type Thread } from "../types" ;
89import { useNativeApi } from "../hooks/useNativeApi" ;
910
1011const THEME_CYCLE = { system : "light" , light : "dark" , dark : "system" } as const ;
@@ -25,11 +26,61 @@ function inferProjectName(cwd: string): string {
2526 return last && last . length > 0 ? last : "project" ;
2627}
2728
28- function threadStatusLabel (
29- status : "connecting" | "ready" | "running" | "error" | "closed" | undefined ,
30- ) : "Working" | "Connecting" | null {
31- if ( status === "running" ) return "Working" ;
32- if ( status === "connecting" ) return "Connecting" ;
29+ interface ThreadStatusPill {
30+ label : "Working" | "Connecting" | "Completed" | "Awaiting response" ;
31+ colorClass : string ;
32+ dotClass : string ;
33+ pulse : boolean ;
34+ }
35+
36+ function hasUnseenCompletion ( thread : Thread ) : boolean {
37+ if ( ! thread . latestTurnCompletedAt ) return false ;
38+ const completedAt = Date . parse ( thread . latestTurnCompletedAt ) ;
39+ if ( Number . isNaN ( completedAt ) ) return false ;
40+ if ( ! thread . lastVisitedAt ) return true ;
41+
42+ const lastVisitedAt = Date . parse ( thread . lastVisitedAt ) ;
43+ if ( Number . isNaN ( lastVisitedAt ) ) return true ;
44+ return completedAt > lastVisitedAt ;
45+ }
46+
47+ function threadStatusPill ( thread : Thread , hasPendingApprovals : boolean ) : ThreadStatusPill | null {
48+ if ( hasPendingApprovals ) {
49+ return {
50+ label : "Awaiting response" ,
51+ colorClass : "text-amber-600 dark:text-amber-300/90" ,
52+ dotClass : "bg-amber-500 dark:bg-amber-300/90" ,
53+ pulse : false ,
54+ } ;
55+ }
56+
57+ if ( thread . session ?. status === "running" ) {
58+ return {
59+ label : "Working" ,
60+ colorClass : "text-sky-600 dark:text-sky-300/80" ,
61+ dotClass : "bg-sky-500 dark:bg-sky-300/80" ,
62+ pulse : true ,
63+ } ;
64+ }
65+
66+ if ( thread . session ?. status === "connecting" ) {
67+ return {
68+ label : "Connecting" ,
69+ colorClass : "text-sky-600 dark:text-sky-300/80" ,
70+ dotClass : "bg-sky-500 dark:bg-sky-300/80" ,
71+ pulse : true ,
72+ } ;
73+ }
74+
75+ if ( hasUnseenCompletion ( thread ) ) {
76+ return {
77+ label : "Completed" ,
78+ colorClass : "text-emerald-600 dark:text-emerald-300/90" ,
79+ dotClass : "bg-emerald-500 dark:bg-emerald-300/90" ,
80+ pulse : false ,
81+ } ;
82+ }
83+
3384 return null ;
3485}
3586
@@ -41,6 +92,13 @@ export default function Sidebar() {
4192 const [ newCwd , setNewCwd ] = useState ( "" ) ;
4293 const [ isPickingFolder , setIsPickingFolder ] = useState ( false ) ;
4394 const [ isAddingProject , setIsAddingProject ] = useState ( false ) ;
95+ const pendingApprovalByThreadId = useMemo ( ( ) => {
96+ const map = new Map < string , boolean > ( ) ;
97+ for ( const thread of state . threads ) {
98+ map . set ( thread . id , derivePendingApprovals ( thread . events ) . length > 0 ) ;
99+ }
100+ return map ;
101+ } , [ state . threads ] ) ;
44102
45103 const handleNewThread = useCallback (
46104 ( projectId : string ) => {
@@ -312,7 +370,10 @@ export default function Sidebar() {
312370 < div className = "ml-2 border-l border-border/80 pl-2" >
313371 { threads . map ( ( thread ) => {
314372 const isActive = state . activeThreadId === thread . id ;
315- const threadStatus = threadStatusLabel ( thread . session ?. status ) ;
373+ const threadStatus = threadStatusPill (
374+ thread ,
375+ pendingApprovalByThreadId . get ( thread . id ) === true ,
376+ ) ;
316377 return (
317378 < button
318379 key = { thread . id }
@@ -338,9 +399,15 @@ export default function Sidebar() {
338399 >
339400 < div className = "flex min-w-0 flex-1 items-center gap-1.5" >
340401 { threadStatus && (
341- < span className = "inline-flex items-center gap-1 text-[10px] text-sky-600 dark:text-sky-300/80" >
342- < span className = "h-1.5 w-1.5 animate-pulse rounded-full bg-sky-500 dark:bg-sky-300/80" />
343- < span className = "hidden xl:inline" > { threadStatus } </ span >
402+ < span
403+ className = { `inline-flex items-center gap-1 text-[10px] ${ threadStatus . colorClass } ` }
404+ >
405+ < span
406+ className = { `h-1.5 w-1.5 rounded-full ${ threadStatus . dotClass } ${
407+ threadStatus . pulse ? "animate-pulse" : ""
408+ } `}
409+ />
410+ < span className = "hidden xl:inline" > { threadStatus . label } </ span >
344411 </ span >
345412 ) }
346413 < span className = "min-w-0 flex-1 truncate text-xs" > { thread . title } </ span >
0 commit comments