Skip to content

ShellJobManager ​

Category: Agent

Source: shell_job_manager.dart

Enums ​

JobStatus ​

ValueDescription
running
failed

Classes ​

sealed JobEvent ​

JobStarted ​

Constructor ​

dart
JobStarted(this.id, this.command)

Properties ​

PropertyTypeDescription
idint
commandString

JobExited ​

Constructor ​

dart
JobExited(this.id, this.exitCode)

Properties ​

PropertyTypeDescription
idint
exitCodeint

JobError ​

Constructor ​

dart
JobError(this.id, this.error)

Properties ​

PropertyTypeDescription
idint
errorObject

ShellJob ​

Constructor ​

dart
ShellJob({
    required this.id,
    required this.command,
    required this.startTime,
    required this.handle,
    required this.output,
    this.traceSpan,
  })

Properties ​

PropertyTypeDescription
idint
commandString
startTimeDateTime
handleRunningCommandHandle
outputLineRingBufferInterleaved stdout and stderr output, capped by the ring buffer limits.
statusJobStatus
exitCodeint?
traceSpanObservabilitySpan?

ShellJobManager ​

Manages the lifecycle of background shell jobs.

Each job's output is captured into a [LineRingBuffer] and status transitions are broadcast as [JobEvent]s, so the UI can update in real time without polling.

Constructor ​

dart
ShellJobManager(this.executor, {this._obs})

Properties ​

PropertyTypeDescription
executorCommandExecutor
eventsStream<JobEvent> get
jobsList<ShellJob> getAll known jobs (running, exited, and killed), sorted by ID (oldest first).
eventsStream<JobEvent> get
jobsList<ShellJob> getAll known jobs (running, exited, and killed), sorted by ID (oldest first).

Methods ​

Future<ShellJob> start(String command) ​

Starts [command] as a background job and begins capturing its output.

Returns immediately with the [ShellJob] handle. Output from both stdout and stderr is fed into the job's [LineRingBuffer], and a [JobStarted] event is emitted on [events].

ShellJob? getJob(int id) ​
Future<void> kill(int id) ​

Sends SIGTERM to the job with the given [id].

No-op if the job doesn't exist or has already exited.

Future<void> shutdown() ​

Tears down the manager, stopping all running jobs.

Sends SIGTERM first and waits briefly for graceful exit, then follows up with SIGKILL for any stubborn processes. The [events] stream is closed after cleanup, so no further events will be emitted.

Released under the MIT License.