pub struct ContextLoader { /* private fields */ }Expand description
Loads AGENTS.md files from the workspace and parent directories.
The loader walks up from the workspace root to the git root (or filesystem
root), collecting AGENTS.md files along the way. It also loads a global
AGENTS.md from ~/.talos/ if it exists.
§Example
use talos_agent::context::ContextLoader;
use std::path::PathBuf;
let loader = ContextLoader::new(PathBuf::from("/path/to/project"));
let context = loader.load().unwrap();Implementations§
Source§impl ContextLoader
impl ContextLoader
Sourcepub fn new(workspace_root: PathBuf) -> Self
pub fn new(workspace_root: PathBuf) -> Self
Creates a new context loader for the given workspace root.
Context loading is enabled by default. Use ContextLoader::with_no_context
to disable it.
Sourcepub fn with_no_context(self) -> Self
pub fn with_no_context(self) -> Self
Disables context loading.
When context loading is disabled, ContextLoader::load returns an
empty string without reading any files.
Sourcepub fn with_global_dir(self, global_dir: PathBuf) -> Self
pub fn with_global_dir(self, global_dir: PathBuf) -> Self
Overrides the directory used to resolve the global AGENTS.md.
When set, the global file is read from <global_dir>/AGENTS.md instead
of the default $HOME/.talos/AGENTS.md. Primarily intended for tests so
they do not need to mutate the process-wide HOME environment variable.
Sourcepub fn load(&self) -> ContextResult<String>
pub fn load(&self) -> ContextResult<String>
Loads and concatenates all AGENTS.md files.
Files are loaded in this order:
- Global:
~/.talos/AGENTS.md(if exists) - Project: walk from
workspace_rootup to git root (or filesystem root), loadingAGENTS.mdfrom each directory
Each file is separated by --- AGENTS.md from {path} ---.
If the total context exceeds 20,000 characters, it is truncated with head (first 10,000) + tail (last 10,000) preservation.
§Errors
Returns ContextError::IoError if a file exists but cannot be read.
Missing files are skipped gracefully.