fn validate_blocks(
file: &str,
user: &UserSection,
tool_ids: &HashSet<String>,
strict_refs: bool,
) -> Result<ExtractedBlocks, PackError>Expand description
Validates and extracts metadata from the fenced blocks in a user section.
This function walks the user’s fenced blocks, validates block sequences and references,
and collects extracted metadata into an ExtractedBlocks struct:
- Tool blocks must contain a single
${...}reference that matches a known tool ID; if followed by a JSON or XML block it is treated as a payload pair (payload must be a${...}ref whenstrict_refsis true). - Standalone JSON or XML blocks are invalid and produce an error.
- Constraints blocks produce one extracted constraint per non-empty, non-comment line.
- Tools blocks list tool IDs (one per line, optionally prefixed with
-) which are validated againsttool_idsand collected intotool_refs. - Rag blocks store their trimmed content as the optional
rag_config. - New config kinds (Adapter, Memory, Policy, Injection, Provider, Cache, Trajectory, Agent, Manifest) are accepted and skipped for later processing.
Errors are returned as PackError::Markdown with file/line context for structural or validation failures.
§Returns
The collected ExtractedBlocks containing constraints, tool_refs, and optional rag_config.
§Examples
ⓘ
use std::collections::HashSet;
// Construct a simple user section with a constraints block
let user = UserSection {
content: String::new(),
blocks: vec![FencedBlock {
kind: FenceKind::Constraints,
header_name: None,
content: "must do X\n# comment\nmust not do Y\n".into(),
line: 1,
}],
};
let tool_ids: HashSet<String> = HashSet::new();
let extracted = validate_blocks("file.md", &user, &tool_ids, false).unwrap();
assert_eq!(extracted.constraints, vec!["must do X".to_string(), "must not do Y".to_string()]);