feat(app): focus attention-needing agent tab on workspace navigation (#828)

When navigating to a workspace, auto-open the tab for the agent that
most urgently needs attention (permission > error > finished, oldest
first). Adds pickAttentionAgent + wires it into navigateToWorkspace.
This commit is contained in:
Mohamed Boudra
2026-05-09 16:07:14 +08:00
committed by GitHub
parent 68ceac492c
commit 103601705d
3 changed files with 199 additions and 1 deletions
+43
View File
@@ -1,3 +1,5 @@
import type { Agent } from "@/stores/session-store";
interface ShouldClearAgentAttentionInput {
agentId: string | null | undefined;
isConnected: boolean;
@@ -13,6 +15,47 @@ export type AgentAttentionClearTrigger =
| "prompt-send"
| "agent-blur";
const ATTENTION_REASON_PRIORITY = {
permission: 0,
error: 1,
finished: 2,
} as const;
function getAttentionPriority(reason: Agent["attentionReason"]): number | null {
if (!reason) {
return null;
}
return ATTENTION_REASON_PRIORITY[reason];
}
export function pickAttentionAgent(agents: Agent[]): string | null {
let selectedAgentId: string | null = null;
let selectedPriority = Number.POSITIVE_INFINITY;
let selectedTimestamp = Number.POSITIVE_INFINITY;
for (const agent of agents) {
if (agent.requiresAttention !== true) {
continue;
}
const priority = getAttentionPriority(agent.attentionReason);
if (priority === null) {
continue;
}
const timestamp = agent.attentionTimestamp?.getTime() ?? Number.POSITIVE_INFINITY;
const isHigherPriority = priority < selectedPriority;
const isOlderAtSamePriority = priority === selectedPriority && timestamp < selectedTimestamp;
if (isHigherPriority || isOlderAtSamePriority) {
selectedAgentId = agent.id;
selectedPriority = priority;
selectedTimestamp = timestamp;
}
}
return selectedAgentId;
}
export function shouldClearAgentAttention(input: ShouldClearAgentAttentionInput): boolean {
const agentId = input.agentId?.trim();
if (!agentId) {