- Rust 99.9%
- Shell 0.1%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| agents | ||
| docs | ||
| src | ||
| test/workspace | ||
| tests | ||
| .gitignore | ||
| AGENTS.md | ||
| Cargo.lock | ||
| Cargo.toml | ||
| Changelog.md | ||
| README.md | ||
agent-parser
A Rust library that parses the YAML frontmatter of the Markdown files defining Agents, Skills, Rules and Hooks for one workspace, keeps them in a registry, renders their instruction bodies with absolute paths, and reloads them instantly when a file changes.
The mdbook in docs/ is the full reference, build it with
mdbook build docs -d docs/book.
Quick start
Load a workspace and read what it holds.
use agent_parser::{AgentInstruction, Registry};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let registry = Registry::load("/home/me/project")?;
for agent in registry.agents() {
println!("{}: {}", agent.name(), agent.description());
println!("{}", agent.instruction()); // body, relative paths now absolute
for missing in agent.validate() {
eprintln!("missing reference: {}", missing.display());
}
}
Ok(())
}
A registry covers one workspace directory and scans only its .agents subtree.
There is no global registry. An item you already hold is a snapshot: a later
reload replaces the registry's entry but leaves your copy serving.
The four categories
Every definition file is Markdown with a YAML frontmatter block. The block opens
with --- and closes at the next ---; everything after it is the body. The
frontmatter always names the item and describes it:
---
name: <registry key> # not the file name — always the frontmatter name
description: one line for a human
# category-specific fields follow
---
| Category | Lives at | For | Category-specific fields |
|---|---|---|---|
| Agent | .agents/<name>.agent.md |
a system prompt the loop carries; it holds the tool permissions, so read it from the original checkout, never a sandbox | called-by, tools, model |
| Skill | .agents/skills/<dir>/SKILL.md |
instructions an agent loads on demand; agents may write and update these inside a sandbox | called-by; extra files live in the directory |
| Rule | .agents/rules/<name>.md |
an instruction the loop inserts around a tool call when an event matches | trigger, repeat, pattern |
| Hook | .agents/hooks/<dir>/HOOK.md |
runs a script or inserts an instruction on a status change | trigger, action, approval-needed; scripts sit next to it as script.* |
The registry key is the frontmatter name. A hook directory named pre-tool
whose frontmatter says name: pre-tool-filter is registered as
pre-tool-filter. Every field, its default, the trigger meanings and the
trigger/action compatibility table are in the
Frontmatter reference.
What the crate does for you
| You want to | Use |
|---|---|
| Load a workspace | Registry::load |
| List or look up items | agents() agent(name), skills() skill(name), rules() rule(name), hooks() hook(name) |
| Hooks for one trigger | hooks_with_trigger(HookTrigger::…) |
| Ask whether an event fires a rule | Rule::matches(&RuleEvent) |
| Render a body with absolute paths | AgentInstruction::instruction |
| List referenced files that do not exist | AgentInstruction::validate |
| React to file edits | Registry::watch |
Agent, Skill, Rule and Hook all implement the object-safe
AgentInstruction trait — name, description, instruction, validate — so
you can hold them as Arc<dyn AgentInstruction> and treat the four categories
uniformly. Rule::matches is the one behavioral helper; the crate exposes rule
and hook trigger data but leaves acting on it to your agent loop.
Path handling
instruction returns the body without frontmatter and with relative paths
resolved to absolute ones, so an agent reading it can always point at a real
path.
- Agents, rules and hooks resolve relative paths against the workspace; skills
resolve against their own
SKILL.mddirectory. - Skills also replace the literal
<workspace>placeholder with the absolute workspace path. - Markdown links, image destinations and inline code spans are rewritten. A code
span only counts when it carries a
/or starts with<workspace>, socargo buildandagent-parserstay as written. Backtick code fences are left alone. validatelists the referenced paths that do not exist. This is informational, not an error: a skill may reference a file it intends to create.
The full rules — including exactly what is scanned and what stays untouched — are on Instructions and paths.
Watching for changes
Registry::watch hands you a tokio UnboundedReceiver<ChangeMessage> and
reloads the changed items itself, reporting one message per item — never per
file — with ChangeKind::Added, Updated, Removed or Failed. A skill's
extra file or a hook's script.* signals the item that owns it. It needs a
current tokio runtime, and dropping the last Registry handle stops the watcher;
there is no cleanup call. Behavior, timing and the shutdown chain are on
Watching for changes.
Behavior you can rely on
- Nothing panics. Every fallible operation returns
Result, and the error type isAgentParserError. - An invalid file never aborts a load. It is skipped and recorded in
Registry::load_errors()with its path and reason. A duplicate name settles by path order: the later file wins, the shadowed one becomes a recorded load error. - Loading and watching are separate. Reading a workspace once never starts a watcher.
Repository layout
| Path | Content |
|---|---|
src |
the crate: frontmatter, model |
, paths, instruction, registry |
|
test/workspace |
committed example workspace the tests run against; tests never modify it |
docs |
the user documentation (mdbook), built to docs/book |
agents |
agent scratch space: plans, rules, memory, reports |
Development
cargo build # build the crate
cargo test --workspace # unit, integration and doc tests
cargo clippy --workspace --all-targets
cargo fmt --check
cargo doc # API reference
mdbook build docs -d docs/book # user documentation
cargo, clippy and mdbook are installed on the host. The mdbook build uses
the mdbook-mermaid preprocessor and the committed docs/mermaid.min.js and
docs/mermaid-init.js, so it works offline.
Runtime dependencies: serde with derive, serde_norway for YAML, regex,
thiserror, log, notify with notify-debouncer-full for the file watch, and
tokio (sync, rt, macros, time) for the change channel. tempfile and
env_logger are development-only dependencies for the tests. See the Tech-stack
section of AGENTS.md.