source dump of claude code
1// Union of all concrete task state types
2// Use this for components that need to work with any task type
3
4import type { DreamTaskState } from './DreamTask/DreamTask.js'
5import type { InProcessTeammateTaskState } from './InProcessTeammateTask/types.js'
6import type { LocalAgentTaskState } from './LocalAgentTask/LocalAgentTask.js'
7import type { LocalShellTaskState } from './LocalShellTask/guards.js'
8import type { LocalWorkflowTaskState } from './LocalWorkflowTask/LocalWorkflowTask.js'
9import type { MonitorMcpTaskState } from './MonitorMcpTask/MonitorMcpTask.js'
10import type { RemoteAgentTaskState } from './RemoteAgentTask/RemoteAgentTask.js'
11
12export type TaskState =
13 | LocalShellTaskState
14 | LocalAgentTaskState
15 | RemoteAgentTaskState
16 | InProcessTeammateTaskState
17 | LocalWorkflowTaskState
18 | MonitorMcpTaskState
19 | DreamTaskState
20
21// Task types that can appear in the background tasks indicator
22export type BackgroundTaskState =
23 | LocalShellTaskState
24 | LocalAgentTaskState
25 | RemoteAgentTaskState
26 | InProcessTeammateTaskState
27 | LocalWorkflowTaskState
28 | MonitorMcpTaskState
29 | DreamTaskState
30
31/**
32 * Check if a task should be shown in the background tasks indicator.
33 * A task is considered a background task if:
34 * 1. It is running or pending
35 * 2. It has been explicitly backgrounded (not a foreground task)
36 */
37export function isBackgroundTask(task: TaskState): task is BackgroundTaskState {
38 if (task.status !== 'running' && task.status !== 'pending') {
39 return false
40 }
41 // Foreground tasks (isBackgrounded === false) are not yet "background tasks"
42 if ('isBackgrounded' in task && task.isBackgrounded === false) {
43 return false
44 }
45 return true
46}