Skip to main content

FrozenContext

Struct FrozenContext 

Source
pub struct FrozenContext {
Show 18 fields pub cwd: PathBuf, pub is_git: bool, pub is_worktree: bool, pub git_branch: Option<String>, pub git_main_branch: Option<String>, pub git_user_name: Option<String>, pub git_status: Option<String>, pub git_log: Option<String>, pub platform: String, pub shell: Option<String>, pub home_dir: Option<String>, pub today: String, pub memory_blocks: Vec<MemoryFileEntry>, pub user_email: Option<String>, pub memory_dir: PathBuf, pub memory_index: Option<String>, pub already_surfaced: HashSet<String>, pub output_style: Option<OutputStyle>,
}
Expand description

会话级冻结的环境信息。一次会话只算一次;turn 之间不变。

Fields§

§cwd: PathBuf§is_git: bool§is_worktree: bool§git_branch: Option<String>§git_main_branch: Option<String>§git_user_name: Option<String>§git_status: Option<String>§git_log: Option<String>§platform: String§shell: Option<String>§home_dir: Option<String>

这台机器上用户的 home 目录——和 platform/shell 一样是环境事实, 进 system prompt 给模型交代环境,不是 Agix 存东西的地方(那些根一律 由调用方注入,见 crate::paths::ConfigPaths)。收进快照而不是在拼 prompt 时现读,是因为快照可以被测试替换,而 env 不能。

§today: String§memory_blocks: Vec<MemoryFileEntry>§user_email: Option<String>§memory_dir: PathBuf

模型写记忆的目录,即 [crate::memory::MemoryStore::for_paths] 的全局一层。

§memory_index: Option<String>

全局与项目两层 MEMORY.md 合起来的索引(截到 8 KB),场景的 memory 提醒带的就是它。

§already_surfaced: HashSet<String>

Memory file paths already surfaced in prior turns. Used to deduplicate and avoid re-injecting the same memories every turn.

§output_style: Option<OutputStyle>

output style 已加载的内容(name 来自 EngineConfig, 由 collect_output_style 从 user/project 级别 output-styles/<name>.md 读取)。None = 没指定或文件不存在。

Implementations§

Source§

impl FrozenContext

Source

pub async fn collect_environment( cwd: PathBuf, opts: &CollectOptions, paths: &ConfigPaths, environment: &dyn Environment, engine_git: &EngineExec, ) -> Self

收集环境快照里不依赖指令文件、记忆库的那部分:git、平台、home、日期、 邮箱、记忆目录。AGENTS.md、记忆索引、output style 由 runtime 填。 所有 IO 错误都吞掉转 None / 默认值;这个函数不该 panic、不该 fail。

Source§

impl FrozenContext

Source

pub async fn refresh_git(&mut self, engine_git: &EngineExec)

Re-run just the git-derived fields (branch/status/log/worktree-ness), leaving memory/skills/output-style untouched. Exists to partially relax this module’s “not refreshed during a session” characteristic for the one field that goes stale fastest in a long-running session — callers are expected to invoke this only after detecting a git-mutating command in the turn just completed (see runtime::turn’s caller), not on every turn: a git status/log/branch re-derivation is real subprocess I/O (bounded by the same 1.5s per-subcommand timeout collect_environment uses), not free.

Source

pub async fn refresh_git_status(&mut self, engine_git: &EngineExec)

Re-derive only git_status and git_branch — the two fields that get re-shown to the model on every turn (git_status through the per-turn <system-reminder>, git_branch through the scene’s <env> block) and therefore the two that must not be a session-start snapshot.

A stale git status is worse than an absent one: the model does not treat it as a possibly-outdated hint, it treats it as current fact, so after a commit it keeps reasoning about files that are no longer dirty and re-suggesting work that is already done. The wider FrozenContext::refresh_git fixes that too, but it is called only after the model itself runs a git-mutating Bash command — which misses every ordinary cause of drift: the user committing in another terminal, an editor writing a file, and the model’s own Write/Edit calls, none of which go through Bash.

Two subcommands rather than refresh_git’s six: git log/main-branch detection/user.name do not appear in anything injected per turn and change far more slowly, so paying for them every turn buys nothing. Skips all I/O when the session is not in a git repository at all — the common non-repo case stays free.

Trait Implementations§

Source§

impl Clone for FrozenContext

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FrozenContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FrozenContext

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more