@@ -230,6 +230,8 @@ def show_agent(agent_ref, home=None):
230230 snapshot ["state" ] = _read_json (agent_dir / "state.json" )
231231 snapshot ["state" ]["child_ids" ] = snapshot ["child_ids" ]
232232 snapshot ["state" ]["unread_message_count" ] = snapshot ["unread_message_count" ]
233+ snapshot ["state" ]["pending_command_count" ] = snapshot ["pending_command_count" ]
234+ snapshot ["state" ]["pending_commands" ] = snapshot ["pending_commands" ]
233235 snapshot ["state" ]["run_lock_held" ] = snapshot ["run_lock_held" ]
234236 snapshot ["state" ]["last_event_at" ] = snapshot ["last_event_at" ]
235237 snapshot ["state" ]["stale" ] = snapshot ["stale" ]
@@ -256,7 +258,8 @@ def status_agent(agent_ref, home=None, include_actions=False):
256258 result = {
257259 "id" : snapshot ["id" ],
258260 "name" : snapshot ["name" ],
259- "agent_status" : snapshot ["status" ],
261+ "agent_status" : snapshot ["display_status" ],
262+ "state_status" : snapshot ["status" ],
260263 "thread_id" : session .get ("thread_id" ) or snapshot .get ("thread_id" ) or "" ,
261264 "rollout_path" : str (rollout_path ) if rollout_path else "" ,
262265 "turn_id" : "" ,
@@ -273,6 +276,9 @@ def status_agent(agent_ref, home=None, include_actions=False):
273276 "stale" : snapshot ["stale" ],
274277 "stale_after_seconds" : snapshot ["stale_after_seconds" ],
275278 "stale_for_seconds" : snapshot ["stale_for_seconds" ],
279+ "pending_command_count" : snapshot ["pending_command_count" ],
280+ "pending_commands" : snapshot ["pending_commands" ],
281+ "queued_message_count" : snapshot ["unread_message_count" ],
276282 }
277283 if rollout_path is None or not rollout_path .exists ():
278284 return result
@@ -1097,13 +1103,17 @@ def _snapshot(agent_dir, child_map=None):
10971103 state = _read_json (agent_dir / "state.json" )
10981104 session = _read_session (agent_dir )
10991105 runtime = _agent_runtime (agent_dir , meta , state , session )
1106+ queued = _queued_commands (agent_dir )
1107+ queued_controls = [item for item in queued if item .get ("kind" ) != "send" ]
1108+ queued_kinds = [item .get ("kind" ) or "" for item in queued_controls if item .get ("kind" )]
11001109 if child_map is None :
11011110 child_ids = _child_map (agent_dir .parents [1 ]).get (meta ["id" ], [])
11021111 else :
11031112 child_ids = child_map .get (meta ["id" ], [])
11041113 unread = int (state .get ("unread_message_count" ) or 0 ) + len (
1105- _queued_send_commands ( agent_dir )
1114+ [ item for item in queued if item . get ( "kind" ) == "send" ]
11061115 )
1116+ status = state .get ("status" ) or ""
11071117 return {
11081118 "id" : meta ["id" ],
11091119 "name" : meta ["name" ],
@@ -1114,13 +1124,21 @@ def _snapshot(agent_dir, child_map=None):
11141124 "cwd" : meta ["cwd" ],
11151125 "stop_policy" : meta ["stop_policy" ],
11161126 "heartbeat_minutes" : meta ["heartbeat_minutes" ],
1117- "status" : state .get ("status" ) or "" ,
1127+ "status" : status ,
1128+ "display_status" : _display_status (
1129+ status ,
1130+ queued_kinds ,
1131+ runtime ["run_lock_held" ],
1132+ runtime ["stale" ],
1133+ ),
11181134 "thread_id" : state .get ("thread_id" ) or "" ,
11191135 "last_wake_at" : state .get ("last_wake_at" ) or "" ,
11201136 "last_success_at" : state .get ("last_success_at" ) or "" ,
11211137 "next_wake_at" : state .get ("next_wake_at" ) or "" ,
11221138 "wake_requested_at" : state .get ("wake_requested_at" ) or "" ,
11231139 "unread_message_count" : unread ,
1140+ "pending_command_count" : len (queued_controls ),
1141+ "pending_commands" : queued_kinds ,
11241142 "input_tokens" : int (state .get ("input_tokens" ) or 0 ),
11251143 "output_tokens" : int (state .get ("output_tokens" ) or 0 ),
11261144 "total_tokens" : int (state .get ("total_tokens" ) or 0 ),
@@ -1554,7 +1572,29 @@ def _usage_int(value):
15541572 return None
15551573
15561574
1557- def _queued_send_commands (agent_dir ):
1575+ def _display_status (status , pending_commands , run_lock_held , stale ):
1576+ """Return a user-facing status that includes queued control intent."""
1577+ state = str (status or "" )
1578+ commands = [str (kind or "" ) for kind in pending_commands or [] if kind ]
1579+ if stale :
1580+ return "stale"
1581+ if commands :
1582+ last = commands [- 1 ]
1583+ if last == "resume" and state in ("paused" , "done" ):
1584+ return "resuming"
1585+ if last == "pause" and state in ("ready" , "error" , "running" ):
1586+ return "pausing"
1587+ if last == "cancel" and state != "canceled" :
1588+ return "canceling"
1589+ if last == "wake" and state in ("ready" , "error" ):
1590+ return "waking"
1591+ if run_lock_held and state == "running" :
1592+ return "running"
1593+ return state or ""
1594+
1595+
1596+ def _queued_commands (agent_dir , kind = None ):
1597+ """Return queued command payloads from commands/new."""
15581598 queued = []
15591599 new_dir = agent_dir / "commands" / "new"
15601600 if not new_dir .exists ():
@@ -1566,11 +1606,17 @@ def _queued_send_commands(agent_dir):
15661606 payload = _read_json (path )
15671607 except (FileNotFoundError , json .JSONDecodeError ):
15681608 continue
1569- if payload .get ("kind" ) == "send" :
1570- queued .append (payload )
1609+ payload_kind = payload .get ("kind" ) or ""
1610+ if kind and payload_kind != kind :
1611+ continue
1612+ queued .append (payload )
15711613 return queued
15721614
15731615
1616+ def _queued_send_commands (agent_dir ):
1617+ return _queued_commands (agent_dir , "send" )
1618+
1619+
15741620def _has_new_commands (agent_dir ):
15751621 new_dir = agent_dir / "commands" / "new"
15761622 if not new_dir .exists ():
0 commit comments