pub struct RunningTask {Show 15 fields
pub task_id: String,
pub typed_id: Option<TaskId>,
pub task_type: TaskType,
pub events_log: Mutex<Vec<String>>,
pub status: Mutex<RunningStatus>,
pub cancel: CancellationToken,
pub started_ms: i64,
pub ended_ms: Mutex<Option<i64>>,
pub detail: Mutex<Value>,
pub announced: AtomicBool,
pub ended: Notify,
pub inbox: OnceLock<Arc<dyn TaskInbox>>,
pub usage: Mutex<Option<Usage>>,
pub structured_output: OnceLock<Value>,
pub waiting_for: Mutex<Vec<String>>,
/* private fields */
}Expand description
一件属于会话、在会话里继续跑的工作:子 Agent、团队成员、执行中的 Shell……
输出(append_output)/ events_log / status 由跑它的那段代码追加;TaskOutput
工具与宿主的 session.taskOutput 读快照,或按字节偏移接着读;
TaskStop 与宿主的 session.stopTask 触发 cancel token。
Fields§
§task_id: String§typed_id: Option<TaskId>§task_type: TaskType§events_log: Mutex<Vec<String>>工具调用与结果的可读日志(每行一条)
status: Mutex<RunningStatus>§cancel: CancellationTokenWhat the work runs under: cancelling it stops the work.
started_ms: i64Unix millis.
ended_ms: Mutex<Option<i64>>Unix millis; None while it runs.
detail: Mutex<Value>What a viewer needs to tell this task from another: the command, the sub-agent’s type, the tool call it belongs to.
announced: AtomicBoolWhether its start was announced; a task that never was ends silently.
ended: NotifyWoken once ended_ms is set — see RunningTask::wait_ended.
inbox: OnceLock<Arc<dyn TaskInbox>>Where messages for the work go while it runs; set by work that can take them (a sub-agent), absent for the rest.
usage: Mutex<Option<Usage>>What the work’s own model calls have cost so far; None for work that
makes none (a shell command).
structured_output: OnceLock<Value>What a sub-agent with an output schema handed in.
waiting_for: Mutex<Vec<String>>The questions the work is waiting on the host to answer, by prompt id.
Implementations§
Source§impl RunningTask
impl RunningTask
Sourcepub const PROGRESS_FRAME_BYTES: usize
pub const PROGRESS_FRAME_BYTES: usize
The most of the new output one task_progress carries.
Sourcepub const OUTPUT_KEPT_BYTES: usize
pub const OUTPUT_KEPT_BYTES: usize
The most of a streamed output (a shell command’s, a monitor’s) a task keeps; beyond it the oldest goes.
Sourcepub fn new(task_id: String, task_type: TaskType) -> Self
pub fn new(task_id: String, task_type: TaskType) -> Self
Create a new running task with defaults.
Sourcepub fn with_cancel(
task_id: String,
task_type: TaskType,
cancel: CancellationToken,
) -> Self
pub fn with_cancel( task_id: String, task_type: TaskType, cancel: CancellationToken, ) -> Self
A running task whose work runs under cancel.
Sourcepub fn report_to(&self, events: Sender<TaskEvent>)
pub fn report_to(&self, events: Sender<TaskEvent>)
Where this task’s task_* events go; set once, by the session that
registers it.
Sourcepub fn begin_waiting(&self, prompt_id: &str)
pub fn begin_waiting(&self, prompt_id: &str)
The work is waiting on the host’s answer to prompt_id.
Sourcepub fn end_waiting(&self, prompt_id: &str)
pub fn end_waiting(&self, prompt_id: &str)
The question prompt_id was answered, or given up on.
Sourcepub fn update_detail(&self, change: impl FnOnce(&mut Value))
pub fn update_detail(&self, change: impl FnOnce(&mut Value))
Change what detail holds, then report task_updated.
Sourcepub fn streams_output(&self) -> bool
pub fn streams_output(&self) -> bool
Whether what the work prints is streamed as it runs (task_progress):
a shell command’s, a monitor’s, a program’s and an MCP task’s status
lines. A sub-agent’s output is its final answer, reported when it
finishes.
Sourcepub fn report_progress(&self)
pub fn report_progress(&self)
Send what the work printed since the last task_progress, if anything.
Nothing goes out once the output is closed, so
none can follow task_finished.
Sourcepub fn close_output(&self) -> bool
pub fn close_output(&self) -> bool
End the output: what the work printed since the last task_progress
goes out as the last one, and nothing is added after. false if it
was already closed.
pub fn output_closed(&self) -> bool
pub fn has_ended(&self) -> bool
Sourcepub async fn wait_ended(&self)
pub async fn wait_ended(&self)
Resolves once the task has ended (at once if it already has).
Sourcepub fn append_output(&self, text: &str)
pub fn append_output(&self, text: &str)
Add to the output as the work produces it, keeping its last
Self::OUTPUT_KEPT_BYTES. Nothing is added once it is closed.
Sourcepub fn output_text(&self) -> String
pub fn output_text(&self) -> String
All of the output still kept.
Sourcepub fn output_tail(&self, max_bytes: usize) -> OutputSlice
pub fn output_tail(&self, max_bytes: usize) -> OutputSlice
The last max_bytes of the output.
Sourcepub fn output_from(&self, from_byte: u64) -> Result<OutputSlice, u64>
pub fn output_from(&self, from_byte: u64) -> Result<OutputSlice, u64>
The output from byte from_byte of everything ever appended to its
end, as much of it as is still kept. Err carries the end when
from_byte is past it.