Count subagents, and keep a batch from looking free
Corrected from the previous commit, which had it backwards. When a batch is running the session is working, not waiting: the main agent will pick the results up and consolidate them itself, so sending you to that terminal wastes the trip. That is the common shape of the work here -- ask for a batch, let it run. Simply letting subagent tool calls set "busy" would mostly work and was tempting, but it leaves a hole. Stop fires before the batch finishes, so the session shows as free from the moment the turn ends until the first subagent tool call lands -- and longer whenever the subagents are thinking rather than calling tools. So subagents are counted instead: PreToolUse, matched to ^(Agent|Task)$ +1 SubagentStop -1 UserPromptSubmit reset to 0 While the count is above zero the session cannot read as waiting; Stop and an idle_prompt nudge both leave it working. The session is freed by the last subagent leaving, and only if the main agent has stopped by then. The matcher is anchored because it is a regex: a bare "Task" also matches TaskCreate and friends, which are not subagents. The hook re-checks the tool name itself in case a future matcher behaves differently, and the reset on UserPromptSubmit bounds a count that leaks because a subagent died without its SubagentStop. Measured, not assumed: a matched PreToolUse fires only on agent launches, SubagentStop arrives once per subagent carrying agent_id, and a real three-subagent run walks the count 0-1-2-3-2-0 before Stop frees it. The menu shows the number, as asked. The panel does not: a batch of eight is still one line saying "working 40 min", which is the right line.
This commit is contained in:
+10
-1
@@ -305,6 +305,15 @@ class ClaudeStatusIndicator extends PanelMenu.Button {
|
||||
|
||||
/** Second line: what the session needs, then where to find it. */
|
||||
_subtitleFor(session) {
|
||||
const what = [stateLabel(session.state)];
|
||||
// A batch is why a session can be working with nothing on its own
|
||||
// plate, and how far along it is decides whether to wait for it.
|
||||
if (session.agents > 0) {
|
||||
what.push(session.agents === 1
|
||||
? _('1 subagent')
|
||||
: `${session.agents} ${_('subagents')}`);
|
||||
}
|
||||
|
||||
const where = [];
|
||||
const tab = this._tabFor(session);
|
||||
if (tab)
|
||||
@@ -320,7 +329,7 @@ class ClaudeStatusIndicator extends PanelMenu.Button {
|
||||
// the tab and the path out of the line to say less than the state
|
||||
// label already does. Getting the real command means reading the tail
|
||||
// of the transcript when the prompt fires; it is not in the event.
|
||||
return `${stateLabel(session.state)} · ${where.join(' · ')}`;
|
||||
return `${what.join(' · ')} · ${where.join(' · ')}`;
|
||||
}
|
||||
|
||||
_ageOf(session) {
|
||||
|
||||
Reference in New Issue
Block a user