highlight active subagents
This commit is contained in:
@@ -95,6 +95,7 @@ type live struct {
|
||||
wantCompact bool
|
||||
rateLimited map[string]any
|
||||
lastText string
|
||||
subagents map[string]bool
|
||||
|
||||
contextModel string
|
||||
contextUsed int
|
||||
@@ -321,6 +322,17 @@ func (m *Manager) Recover(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
stale, err := m.store.SessionsWithSubagents(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, sess := range stale {
|
||||
err = m.store.SetSubagents(ctx, sess.Id, 0, "byre")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
sessions, err := m.store.SessionsInState(ctx, api.AgentSessionStateRunning)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -686,6 +698,7 @@ func (m *Manager) startLive(ctx context.Context, sess api.AgentSession, task api
|
||||
taskID: task.Id,
|
||||
projectID: task.ProjectId,
|
||||
owner: sess.Owner,
|
||||
subagents: map[string]bool{},
|
||||
}
|
||||
|
||||
g, err := m.taskGuidance(ctx, task)
|
||||
@@ -764,9 +777,17 @@ func (m *Manager) pump(l *live) {
|
||||
|
||||
m.mu.Lock()
|
||||
delete(m.live, l.id)
|
||||
quiet := m.closing || l.stopping
|
||||
closing := m.closing
|
||||
quiet := closing || l.stopping
|
||||
m.mu.Unlock()
|
||||
|
||||
if len(l.subagents) > 0 && !closing {
|
||||
err := m.store.SetSubagents(ctx, l.id, 0, "byre")
|
||||
if err != nil {
|
||||
slog.Error("clear exited session's subagents", "session", l.id, "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
if quiet {
|
||||
m.logUndelivered(ctx, l.id, "agent process ended while closing or stopping")
|
||||
return
|
||||
@@ -934,7 +955,31 @@ func (m *Manager) handle(ctx context.Context, l *live, ev claude.Event) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return m.emit(ctx, l, agentActor, "agent.vendor", raw)
|
||||
err = m.emit(ctx, l, agentActor, "agent.vendor", raw)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return m.trackSubagents(ctx, l, raw)
|
||||
}
|
||||
|
||||
func (m *Manager) trackSubagents(ctx context.Context, l *live, raw map[string]any) error {
|
||||
if raw["type"] != "system" {
|
||||
return nil
|
||||
}
|
||||
id, _ := raw["task_id"].(string)
|
||||
n := len(l.subagents)
|
||||
switch raw["subtype"] {
|
||||
case "task_started":
|
||||
if raw["task_type"] == "local_agent" {
|
||||
l.subagents[id] = true
|
||||
}
|
||||
case "task_notification":
|
||||
delete(l.subagents, id)
|
||||
}
|
||||
if len(l.subagents) == n {
|
||||
return nil
|
||||
}
|
||||
return m.store.SetSubagents(ctx, l.id, len(l.subagents), agentActor)
|
||||
}
|
||||
|
||||
type endResult struct {
|
||||
|
||||
Reference in New Issue
Block a user