@@ -102,6 +102,50 @@ func TestScanAgents_NestedSubagents(t *testing.T) {
102102 }
103103}
104104
105+ func TestScanAgents_NestedSorting (t * testing.T ) {
106+ dir := t .TempDir ()
107+
108+ // Create nested subagent that is active (recent mod time)
109+ sessionDir := filepath .Join (dir , "session-1" , "subagents" )
110+ os .MkdirAll (sessionDir , 0755 )
111+ f1 , _ := os .Create (filepath .Join (sessionDir , "agent-active.jsonl" ))
112+ f1 .WriteString (`{"type":"user","message":{"role":"user","content":"Active task"}}` )
113+ f1 .Close ()
114+ // Leave mod time as now (active)
115+
116+ // Create root-level agent that is inactive
117+ f2 , _ := os .Create (filepath .Join (dir , "agent-inactive.jsonl" ))
118+ f2 .WriteString (`{"type":"user","message":{"role":"user","content":"Inactive task"}}` )
119+ f2 .Close ()
120+ oldTime := time .Now ().Add (- 1 * time .Hour )
121+ os .Chtimes (filepath .Join (dir , "agent-inactive.jsonl" ), oldTime , oldTime )
122+
123+ agents , err := ScanAgents (dir )
124+ if err != nil {
125+ t .Fatalf ("ScanAgents: %v" , err )
126+ }
127+
128+ if len (agents ) != 2 {
129+ t .Fatalf ("got %d agents, want 2" , len (agents ))
130+ }
131+
132+ // Active nested agent should be first
133+ if agents [0 ].ID != "active" {
134+ t .Errorf ("first agent should be 'active', got %q" , agents [0 ].ID )
135+ }
136+ if ! agents [0 ].IsActive () {
137+ t .Error ("first agent should be active" )
138+ }
139+
140+ // Inactive root agent should be second
141+ if agents [1 ].ID != "inactive" {
142+ t .Errorf ("second agent should be 'inactive', got %q" , agents [1 ].ID )
143+ }
144+ if agents [1 ].IsActive () {
145+ t .Error ("second agent should be inactive" )
146+ }
147+ }
148+
105149func TestAgentIsActive (t * testing.T ) {
106150 agent := Agent {
107151 LastMod : time .Now ().Add (- 5 * time .Second ),
0 commit comments