/ tasks / LocalShellTask / guards.ts
guards.ts
 1  // Pure type + type guard for LocalShellTask state.
 2  // Extracted from LocalShellTask.tsx so non-React consumers (stopTask.ts via
 3  // print.ts) don't pull React/ink into the module graph.
 4  
 5  import type { TaskStateBase } from '../../Task.js'
 6  import type { AgentId } from '../../types/ids.js'
 7  import type { ShellCommand } from '../../utils/ShellCommand.js'
 8  
 9  export type BashTaskKind = 'bash' | 'monitor'
10  
11  export type LocalShellTaskState = TaskStateBase & {
12    type: 'local_bash' // Keep as 'local_bash' for backward compatibility with persisted session state
13    command: string
14    result?: {
15      code: number
16      interrupted: boolean
17    }
18    completionStatusSentInAttachment: boolean
19    shellCommand: ShellCommand | null
20    unregisterCleanup?: () => void
21    cleanupTimeoutId?: NodeJS.Timeout
22    // Track what we last reported for computing deltas (total lines from TaskOutput)
23    lastReportedTotalLines: number
24    // Whether the task has been backgrounded (false = foreground running, true = backgrounded)
25    isBackgrounded: boolean
26    // Agent that spawned this task. Used to kill orphaned bash tasks when the
27    // agent exits (see killShellTasksForAgent). Undefined = main thread.
28    agentId?: AgentId
29    // UI display variant. 'monitor' → shows description instead of command,
30    // 'Monitor details' dialog title, distinct status bar pill.
31    kind?: BashTaskKind
32  }
33  
34  export function isLocalShellTask(task: unknown): task is LocalShellTaskState {
35    return (
36      typeof task === 'object' &&
37      task !== null &&
38      'type' in task &&
39      task.type === 'local_bash'
40    )
41  }