Parser for Markdown definitions of Agents, Skills, Rules and Hooks
  • Rust 99.9%
  • Shell 0.1%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-11-23 02:51:29 +01:00
agents Bugfix B002: release the watch slot on unwind, document the real unwatch contract 2026-11-23 02:51:21 +01:00
docs Bugfix B002: release the watch slot on unwind, document the real unwatch contract 2026-11-23 02:51:21 +01:00
src Bugfix B002: release the watch slot on unwind, document the real unwatch contract 2026-11-23 02:51:21 +01:00
test/workspace Documentation P001, T009: record the doctest facts and fix the duplicate-rule fixture prose to state the later-file-wins rule 2026-11-03 15:52:31 +01:00
tests Bugfix B003: carry the originating workspace on every ChangeMessage 2026-11-23 02:31:11 +01:00
.gitignore Initial commit, Agent scaffold 2026-11-02 02:18:48 +01:00
AGENTS.md Docs, B001-B003: file downstream bug reports for the watch machinery and add changelog convention 2026-11-23 01:19:10 +01:00
Cargo.lock Feature P001, T001: declare the consented dependency set in the manifest 2026-11-03 02:06:31 +01:00
Cargo.toml Refactor P001, T009: drop the cargo unused_dependencies allowance, every consented dependency is used and a clean build and clippy run report nothing 2026-11-03 15:52:35 +01:00
Changelog.md Bugfix B002: release the watch slot on unwind, document the real unwatch contract 2026-11-23 02:51:21 +01:00
README.md De-Slop docs 2026-11-03 21:33:44 +01:00

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.md directory.
  • 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>, so cargo build and agent-parser stay as written. Backtick code fences are left alone.
  • validate lists 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 is AgentParserError.
  • 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.