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
impl FrozenContext
Sourcepub async fn collect_environment(
cwd: PathBuf,
opts: &CollectOptions,
paths: &ConfigPaths,
environment: &dyn Environment,
engine_git: &EngineExec,
) -> Self
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
impl FrozenContext
Sourcepub async fn refresh_git(&mut self, engine_git: &EngineExec)
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.
Sourcepub async fn refresh_git_status(&mut self, engine_git: &EngineExec)
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.