Skip to main content

Session

Trait Session 

Source
pub trait Session:
    Send
    + Sync
    + Debug {
Show 31 methods // Required methods fn env(&self) -> Arc<SessionEnv> ⓘ; fn exec(&self) -> Option<ExecProviders>; fn tool(&self, name: &str) -> Option<Arc<dyn Tool>>; fn permission_mode(&self) -> PermissionMode; fn set_permission_mode(&self, mode: PermissionMode); fn enter_plan_mode(&self); fn exit_plan_mode(&self) -> PermissionMode; fn host_permission_mode(&self) -> Option<PermissionMode>; fn model_choice(&self) -> Option<String>; fn register_task( &self, task_id: String, task_type: TaskType, cancel: CancellationToken, detail: Value, ) -> Arc<RunningTask> ⓘ; fn finish_task(&self, task_id: &str, status: RunningStatus); fn find_running_task(&self, task_id: &str) -> Option<Arc<RunningTask>>; fn cancel_running_task(&self, task_id: &str) -> bool; fn running_background_task_ids(&self) -> Vec<String>; fn task_infos(&self) -> Vec<TaskInfo>; fn post_notice(&self, key: Option<String>, text: String); fn retract_notice(&self, key: &str) -> bool; fn take_notices(&self) -> Vec<String>; fn record_read(&self, read: ReadRecord<'_>); fn record_write(&self, path: &Path); fn check_read_staleness(&self, path: &Path) -> Option<&'static str>; fn check_read_dedup_with_range( &self, path: &Path, offset: Option<usize>, limit: Option<usize>, ) -> Option<HeldRead>; fn is_consecutive_read(&self, path: &Path) -> bool; fn todos(&self) -> Vec<TodoItem>; fn set_todos(&self, items: Vec<TodoItem>); fn activated_tools(&self) -> HashSet<String>; fn activate_tools(&self, names: Vec<String>); fn ledger(&self) -> MutexGuard<'_, SessionLedger>; fn goal_view(&self) -> Option<GoalView>; fn goal_create( &self, objective: String, limits: GoalLimits, origin: TurnOrigin, ) -> Result<GoalView, GoalError>; fn goal_update( &self, goal_id: &str, revision: u64, action: GoalAction, origin: TurnOrigin, max_rounds_limit: u32, ) -> Result<GoalView, GoalError>;
}
Expand description

What tools and permission policies see of the session they run in. The layering needs the trait, not an extension point: session-state holds the one implementation.

Required Methods§

Source

fn env(&self) -> Arc<SessionEnv> ⓘ

What the attached engine derived from its settings and scene; empty until one is attached.

Source

fn exec(&self) -> Option<ExecProviders>

The providers the attached engine’s tool calls run on, if one is attached.

Source

fn tool(&self, name: &str) -> Option<Arc<dyn Tool>>

The tool this session’s calls named name dispatch to, if the attached engine’s registry holds it.

Source

fn permission_mode(&self) -> PermissionMode

读当前模式。

Source

fn set_permission_mode(&self, mode: PermissionMode)

直接设模式,并忘掉进入计划模式前的那个。

Source

fn enter_plan_mode(&self)

进计划模式,记下进入前的模式给 exit_plan_mode。 已经在计划模式里时什么都不改。

Source

fn exit_plan_mode(&self) -> PermissionMode

退出计划模式,回到进入前的模式;会话一开始就在计划模式里的回到 Default。

Source

fn host_permission_mode(&self) -> Option<PermissionMode>

The mode outside plan a host switched the session to since its engine was attached; None leaves it to the engine’s settings. What a delegate spawned now starts from.

Source

fn model_choice(&self) -> Option<String>

The model the session’s next call asks for, when a host chose one; None leaves it on the model its engine was built with.

Source

fn register_task( &self, task_id: String, task_type: TaskType, cancel: CancellationToken, detail: Value, ) -> Arc<RunningTask> ⓘ

Register work this session is running, under cancel — the token the work itself observes, so stopping the task stops the work.

Its start is announced at once, except a shell command’s or a monitor’s: most of those finish in milliseconds, and a list that flickered with each one would hide the ones worth seeing. Those are announced only if still running a second later, and a task never announced ends without a word. From then on what they print goes out as task_progress, at most once a second, and once more as they end.

Source

fn finish_task(&self, task_id: &str, status: RunningStatus)

Record that a task’s work is over, having ended with status: its output closes and task_finished goes out. A task already ended — stopped by cancel_running_task, say, before its own code got here — keeps the ending it has. Finished tasks beyond the newest few are forgotten.

Source

fn find_running_task(&self, task_id: &str) -> Option<Arc<RunningTask>>

找一个 running task。返回 Arc 让 caller 读快照(output / status)。

Source

fn cancel_running_task(&self, task_id: &str) -> bool

Stop a running task: cancel what it runs under and record it as stopped. false if there is no such task or it had already ended.

task_finished waits for the work to wind down — what it prints on the way out is part of its output — up to a grace period.

Source

fn running_background_task_ids(&self) -> Vec<String>

Ids of the background work still running — sub-agents, teammates, programs, monitors; not a foreground shell command — sorted.

Source

fn task_infos(&self) -> Vec<TaskInfo>

Every task this session knows — running, and the most recently ended — oldest first.

Source

fn post_notice(&self, key: Option<String>, text: String)

Tell this session’s agent something it did not ask for in this turn, such as a background sub-agent having finished. A running turn reads it at its next step boundary; otherwise the next turn opens with it.

A notice under key can be retracted before it is read: one about a task the agent has since waited for tells it nothing new.

Source

fn retract_notice(&self, key: &str) -> bool

Withdraw the unread notice under key; false if there was none — never posted, or already read.

Source

fn take_notices(&self) -> Vec<String>

Source

fn record_read(&self, read: ReadRecord<'_>)

Record what Read just showed the model, with the file’s mtime: a later read of the same range of an unchanged file is answered from the cache while that result is still in the model’s context, and Edit/Write know the file was read and when.

Source

fn record_write(&self, path: &Path)

Record that Edit / Write just changed path, so the next edit of it does not ask for a Read first or call the session’s own change an outside one.

Source

fn check_read_staleness(&self, path: &Path) -> Option<&'static str>

检查文件是否已读且未过期。

  • 文件不存在于磁盘 → 跳过检查(返回 None)
  • 文件已读且 mtime 一致 → 返回 None(通过)
  • 文件未读 → 返回 “must be read” 错误信息
  • 文件已读但 mtime 不同 → 返回 “modified since read” 错误信息
Source

fn check_read_dedup_with_range( &self, path: &Path, offset: Option<usize>, limit: Option<usize>, ) -> Option<HeldRead>

How the model still holds an earlier read of exactly this offset/limit range of path, unchanged since; None when it does not, and the file must be read again.

Source

fn is_consecutive_read(&self, path: &Path) -> bool

给定路径是否与最近一次读取的文件一致。 仅检查路径相等;mtime 一致性由调用方通过 check_read_dedup_with_range 保证。

Source

fn todos(&self) -> Vec<TodoItem>

读取当前 todo 列表(克隆给调用方)

Source

fn set_todos(&self, items: Vec<TodoItem>)

TodoWrite 工具用:一次性替换整个列表。 如果全部 completed 则自动清空。

Source

fn activated_tools(&self) -> HashSet<String>

当前已激活的 deferred 工具名(克隆 set;调用方只读)。

Source

fn activate_tools(&self, names: Vec<String>)

ToolSearch 命中后调用:把工具加进 activated 集合。 多次调用 idempotent;空集合也允许。

Source

fn ledger(&self) -> MutexGuard<'_, SessionLedger>

Source

fn goal_view(&self) -> Option<GoalView>

The goal as hosts and the model see it.

Source

fn goal_create( &self, objective: String, limits: GoalLimits, origin: TurnOrigin, ) -> Result<GoalView, GoalError>

Source

fn goal_update( &self, goal_id: &str, revision: u64, action: GoalAction, origin: TurnOrigin, max_rounds_limit: u32, ) -> Result<GoalView, GoalError>

An edit may give the goal no more than max_rounds_limit rounds.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§