Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(deps): replace unmaintained serde_yaml with serde-saphyr
AkitaOnRails615689527fdc
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 15f56c48..550d3059 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0## [Unreleased]+### Fixed+- Replaced the unmaintained YAML library (`serde_yaml` and its+ `unsafe-libyaml` parser, RUSTSEC-2024-0449) with `serde-saphyr` for wiki+ page frontmatter, in the server and in `ai-memory-importer`. Existing+ frontmatter parses to the same values as before. One formatting change:+ when a page is next saved, a frontmatter value that needs quoting (a title+ containing `: `, for example) is written in double quotes instead of+ single quotes.+## [2.6.5] - 2026-10-12### Fixeddiff --git a/Cargo.lock b/Cargo.lockindex 9763a546..8d3748ea 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -118,8 +118,8 @@ dependencies = ["regex","schemars","serde",+ "serde-saphyr","serde_json",- "serde_yaml","thiserror 2.0.18","tracing","uuid",@@ -314,8 +314,8 @@ dependencies = ["reqwest 0.12.28","rusqlite","serde",+ "serde-saphyr","serde_json",- "serde_yaml","tar","tempfile","thiserror 2.0.18",@@ -356,6 +356,17 @@ dependencies = ["libc",]+[[package]]+name = "annotate-snippets"+version = "0.12.16"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f211a51805bc641f3ad5b7664c77d2547af685cc33b4cd8d31964027a46f13f1"+dependencies = [+ "anstyle",+ "memchr",+ "unicode-width",+]+[[package]]name = "anstream"version = "1.0.0"@@ -424,6 +435,12 @@ dependencies = ["password-hash",]+[[package]]+name = "arraydeque"+version = "0.5.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7d902e3d592a523def97af8f317b08ce16b7ab854c1985a0c671e6f15cebc236"+[[package]]name = "askama"version = "0.12.1"@@ -888,6 +905,12 @@ version = "0.8.7"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"+[[package]]+name = "core_detect"+version = "1.0.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7f8f80099a98041a3d1622845c271458a2d73e688351bf3cb999266764b81d48"+[[package]]name = "cpufeatures"version = "0.2.17"@@ -1230,6 +1253,29 @@ version = "1.16.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "91622ff5e7162018101f2fea40d6ebf4a78bbe5a49736a2020649edf9693679e"+[[package]]+name = "encoding_rs"+version = "0.8.42"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8e985e0451871ad22fb8d2b6b076e2028a502a0d3950998c2c5c0a4f9b5d9679"+dependencies = [+ "cfg-if",+ "core_detect",+ "multiversion_no_op",+ "rustversion",+ "scopeguard",+ "simdutf8",+]++[[package]]+name = "encoding_rs_io"+version = "0.1.8"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "fba3fe847045ecff794b9c138293a80db914678c453ad63fbf0c6a9eb6e00b22"+dependencies = [+ "encoding_rs",+]+[[package]]name = "enum-as-inner"version = "0.6.1"@@ -1694,6 +1740,16 @@ version = "0.3.4"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "e4eba85ea1d0a966a983acd07deee566e67395d2d96b6fb39e62b5a833f1eb0b"+[[package]]+name = "granit-parser"+version = "1.3.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e20f99e46474f56bd905c56e817ebddcf377a611f94c53ac4649e4d3fa3c0cd0"+dependencies = [+ "arraydeque",+ "smallvec",+]+[[package]]name = "h2"version = "0.4.16"@@ -2475,6 +2531,18 @@ dependencies = ["syn 2.0.117",]+[[package]]+name = "multiversion_no_op"+version = "1.0.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "743fb55ba31b18fb1ecef6bdc9aa2743314978ac084044301a7eee33fb99a20d"++[[package]]+name = "nohash-hasher"+version = "0.2.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451"+[[package]]name = "nom"version = "7.1.3"@@ -3554,6 +3622,23 @@ dependencies = ["serde_derive",]+[[package]]+name = "serde-saphyr"+version = "1.3.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b8050abb251097357e24aff63ba2c52a6309ecb7d23a5474023df960a02694d8"+dependencies = [+ "annotate-snippets",+ "base64 0.22.1",+ "encoding_rs_io",+ "granit-parser",+ "nohash-hasher",+ "num-traits",+ "serde_core",+ "smallvec",+ "zmij",+]+[[package]]name = "serde_core"version = "1.0.228"@@ -3640,19 +3725,6 @@ dependencies = ["serde",]-[[package]]-name = "serde_yaml"-version = "0.9.34+deprecated"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47"-dependencies = [- "indexmap",- "itoa",- "ryu",- "serde",- "unsafe-libyaml",-]-[[package]]name = "sha1_smol"version = "1.0.1"@@ -4385,6 +4457,12 @@ version = "1.13.3"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "c6f5d3c3b1bf09027a88a6bc961fc00497d651009560b5463668dc81b0fa87a8"+[[package]]+name = "unicode-width"+version = "0.2.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254"+[[package]]name = "unicode-xid"version = "0.2.6"@@ -4397,12 +4475,6 @@ version = "0.1.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e"-[[package]]-name = "unsafe-libyaml"-version = "0.2.11"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861"-[[package]]name = "untrusted"version = "0.9.0"diff --git a/Cargo.toml b/Cargo.tomlindex 5602e301..7f3173a7 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -69,7 +69,8 @@ serde = { version = "1", features = ["derive"] }# alphabetised on every write — semantically equivalent but a giant# cosmetic diff the user didn't ask for.serde_json = { version = "1", features = ["preserve_order"] }-serde_yaml = "0.9"+# Wiki frontmatter YAML. Each crate opts into the half it uses.+serde-saphyr = { version = "1.3", default-features = false }# Zed's settings.json is JSONC despite the .json suffix. Its CST lets# install/uninstall preserve comments, trailing commas, and unrelated layout.jsonc-parser = { version = "0.33", features = ["cst", "serde_json"] }diff --git a/companions/ai-memory-importer/Cargo.lock b/companions/ai-memory-importer/Cargo.lockindex 54e87ace..f228fa05 100644--- a/companions/ai-memory-importer/Cargo.lock+++ b/companions/ai-memory-importer/Cargo.lock@@ -29,8 +29,8 @@ dependencies = ["clap","reqwest","serde",+ "serde-saphyr","serde_json",- "serde_yaml","sha2","tempfile","tokio",@@ -38,6 +38,17 @@ dependencies = ["walkdir",]+[[package]]+name = "annotate-snippets"+version = "0.12.16"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f211a51805bc641f3ad5b7664c77d2547af685cc33b4cd8d31964027a46f13f1"+dependencies = [+ "anstyle",+ "memchr",+ "unicode-width",+]+[[package]]name = "anstream"version = "1.0.0"@@ -94,12 +105,24 @@ version = "1.0.102"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c"+[[package]]+name = "arraydeque"+version = "0.5.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7d902e3d592a523def97af8f317b08ce16b7ab854c1985a0c671e6f15cebc236"+[[package]]name = "atomic-waker"version = "1.1.2"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"+[[package]]+name = "autocfg"+version = "1.5.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"+[[package]]name = "base64"version = "0.22.1"@@ -217,6 +240,12 @@ version = "0.8.7"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"+[[package]]+name = "core_detect"+version = "1.0.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7f8f80099a98041a3d1622845c271458a2d73e688351bf3cb999266764b81d48"+[[package]]name = "cpufeatures"version = "0.2.17"@@ -258,10 +287,27 @@ dependencies = [][[package]]-name = "equivalent"-version = "1.0.2"+name = "encoding_rs"+version = "0.8.42"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"+checksum = "8e985e0451871ad22fb8d2b6b076e2028a502a0d3950998c2c5c0a4f9b5d9679"+dependencies = [+ "cfg-if",+ "core_detect",+ "multiversion_no_op",+ "rustversion",+ "scopeguard",+ "simdutf8",+]++[[package]]+name = "encoding_rs_io"+version = "0.1.8"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "fba3fe847045ecff794b9c138293a80db914678c453ad63fbf0c6a9eb6e00b22"+dependencies = [+ "encoding_rs",+][[package]]name = "errno"@@ -376,10 +422,14 @@ dependencies = [][[package]]-name = "hashbrown"-version = "0.17.1"+name = "granit-parser"+version = "1.3.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"+checksum = "e20f99e46474f56bd905c56e817ebddcf377a611f94c53ac4649e4d3fa3c0cd0"+dependencies = [+ "arraydeque",+ "smallvec",+][[package]]name = "heck"@@ -588,16 +638,6 @@ dependencies = ["icu_properties",]-[[package]]-name = "indexmap"-version = "2.14.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9"-dependencies = [- "equivalent",- "hashbrown",-]-[[package]]name = "ipnet"version = "2.12.0"@@ -674,6 +714,21 @@ dependencies = ["windows-sys 0.61.2",]+[[package]]+name = "multiversion_no_op"+version = "1.0.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "743fb55ba31b18fb1ecef6bdc9aa2743314978ac084044301a7eee33fb99a20d"++[[package]]+name = "num-traits"+version = "0.2.19"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"+dependencies = [+ "autocfg",+]+[[package]]name = "once_cell"version = "1.21.4"@@ -1013,6 +1068,12 @@ dependencies = ["windows-sys 0.61.2",]+[[package]]+name = "scopeguard"+version = "1.2.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"+[[package]]name = "security-framework"version = "3.7.0"@@ -1046,6 +1107,20 @@ dependencies = ["serde_derive",]+[[package]]+name = "serde-saphyr"+version = "1.3.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b8050abb251097357e24aff63ba2c52a6309ecb7d23a5474023df960a02694d8"+dependencies = [+ "annotate-snippets",+ "encoding_rs_io",+ "granit-parser",+ "num-traits",+ "serde_core",+ "smallvec",+]+[[package]]name = "serde_core"version = "1.0.228"@@ -1091,19 +1166,6 @@ dependencies = ["serde",]-[[package]]-name = "serde_yaml"-version = "0.9.34+deprecated"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47"-dependencies = [- "indexmap",- "itoa",- "ryu",- "serde",- "unsafe-libyaml",-]-[[package]]name = "sha2"version = "0.10.9"@@ -1121,6 +1183,12 @@ version = "2.0.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"+[[package]]+name = "simdutf8"+version = "0.1.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e"+[[package]]name = "slab"version = "0.4.12"@@ -1369,10 +1437,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"[[package]]-name = "unsafe-libyaml"-version = "0.2.11"+name = "unicode-width"+version = "0.2.2"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861"+checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254"[[package]]name = "untrusted"diff --git a/companions/ai-memory-importer/Cargo.toml b/companions/ai-memory-importer/Cargo.tomlindex eda1363a..ce1d161d 100644--- a/companions/ai-memory-importer/Cargo.toml+++ b/companions/ai-memory-importer/Cargo.toml@@ -15,7 +15,7 @@ clap = { version = "4", features = ["derive", "env"] }reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls-native-roots"] }serde = { version = "1", features = ["derive"] }serde_json = "1"-serde_yaml = "0.9"+serde-saphyr = { version = "1.3", default-features = false, features = ["deserialize"] }sha2 = "0.10"tokio = { version = "1", features = ["macros", "rt-multi-thread"] }url = "2"diff --git a/companions/ai-memory-importer/src/main.rs b/companions/ai-memory-importer/src/main.rsindex 98f0093f..c3c7a2d8 100644--- a/companions/ai-memory-importer/src/main.rs+++ b/companions/ai-memory-importer/src/main.rs@@ -1075,9 +1075,10 @@ fn parse_markdown(input: &str) -> Result<ParsedMarkdown> {let body = if let Some(rest) = rest {if let Some(end) = rest.find(&close) {let yaml = rest[..end].trim_end_matches('\r');- let value: serde_yaml::Value =- serde_yaml::from_str(yaml).context("parse YAML frontmatter")?;- if let Some(map) = value.as_mapping() {+ let value: serde_json::Value =+ serde_saphyr::from_str_with_options(yaml, frontmatter_parse_options())+ .context("parse YAML frontmatter")?;+ if let Some(map) = value.as_object() {out.title = yaml_string(map, "title");out.kind = yaml_string(map, "kind");out.tier = yaml_string(map, "tier");@@ -1098,21 +1099,35 @@ fn parse_markdown(input: &str) -> Result<ParsedMarkdown> {Ok(out)}-fn yaml_key(key: &str) -> serde_yaml::Value {- serde_yaml::Value::String(key.into())+/// Read frontmatter the way `serde_yaml` 0.9 did, matching the server's+/// parser: YAML 1.2 booleans (`pinned: yes` stays a string, so not pinned),+/// `<<` as an ordinary key, and `.inf`/`.nan` kept as text instead of+/// failing the page.+fn frontmatter_parse_options() -> serde_saphyr::Options {+ serde_saphyr::options! {+ strict_booleans: true,+ merge_keys: serde_saphyr::MergeKeyPolicy::AsOrdinary,+ ignore_binary_tag_for_string: true,+ reject_non_finite_typeless_float: false,+ with_snippet: false,+ budget: serde_saphyr::budget! { max_depth: 128 },+ }}-fn yaml_string(map: &serde_yaml::Mapping, key: &str) -> Option<String> {- map.get(yaml_key(key))++type YamlMap = serde_json::Map<String, serde_json::Value>;++fn yaml_string(map: &YamlMap, key: &str) -> Option<String> {+ map.get(key).and_then(|v| v.as_str()).map(str::to_owned).filter(|s| !s.trim().is_empty())}-fn yaml_bool(map: &serde_yaml::Mapping, key: &str) -> Option<bool> {- map.get(yaml_key(key)).and_then(|v| v.as_bool())+fn yaml_bool(map: &YamlMap, key: &str) -> Option<bool> {+ map.get(key).and_then(|v| v.as_bool())}-fn yaml_tags(map: &serde_yaml::Mapping) -> Vec<String> {- match map.get(yaml_key("tags")) {- Some(serde_yaml::Value::Sequence(seq)) => seq+fn yaml_tags(map: &YamlMap) -> Vec<String> {+ match map.get("tags") {+ Some(serde_json::Value::Array(seq)) => seq.iter().filter_map(|v| v.as_str().map(str::to_owned)).collect(),@@ -1439,6 +1454,18 @@ mod tests {assert_eq!(parsed.body, "# Body\ntext");}+ /// `serde_yaml` 0.9 read YAML 1.1 words as text, so `pinned: yes` never+ /// pinned a page and a bare `tags:` word stayed a one-item list.+ #[test]+ fn omc_frontmatter_keeps_yaml_1_1_words_as_text() {+ let parsed = parse_markdown("---\ntitle: yes\npinned: yes\ntags: on\n---\nbody").unwrap();+ assert_eq!(parsed.title.as_deref(), Some("yes"));+ assert!(!parsed.pinned);+ assert_eq!(parsed.tags, vec!["on"]);++ assert!(parse_markdown("---\ntitle: a\ntitle: b\n---\nbody").is_err());+ }+/// A wiki checked out on Windows with `core.autocrlf=true`, or saved/// there by an editor, has CRLF line endings; one saved as "UTF-8 with/// BOM" opens with U+FEFF. Either used to miss the fence, so kind, tier,diff --git a/crates/ai-memory-core/Cargo.toml b/crates/ai-memory-core/Cargo.tomlindex 3d6a5f7d..a2c25bd0 100644--- a/crates/ai-memory-core/Cargo.toml+++ b/crates/ai-memory-core/Cargo.toml@@ -24,7 +24,7 @@ tracing.workspace = trueschemars.workspace = true[dev-dependencies]-serde_yaml.workspace = true+serde-saphyr = { workspace = true, features = ["deserialize"] }[lints]workspace = truediff --git a/crates/ai-memory-core/src/routing_skills.rs b/crates/ai-memory-core/src/routing_skills.rsindex 51113526..7223c595 100644--- a/crates/ai-memory-core/src/routing_skills.rs+++ b/crates/ai-memory-core/src/routing_skills.rs@@ -277,7 +277,7 @@ mod tests {let Some((frontmatter, _body)) = rest.split_once("\n---\n") else {panic!("{} must close frontmatter", skill.name);};- serde_yaml::from_str(frontmatter)+ serde_saphyr::from_str(frontmatter).unwrap_or_else(|e| panic!("{} frontmatter must be valid YAML: {e}", skill.name))}diff --git a/crates/ai-memory-wiki/Cargo.toml b/crates/ai-memory-wiki/Cargo.tomlindex fcdd638d..997274a5 100644--- a/crates/ai-memory-wiki/Cargo.toml+++ b/crates/ai-memory-wiki/Cargo.toml@@ -16,7 +16,7 @@ anyhow.workspace = truethiserror.workspace = trueserde.workspace = trueserde_json.workspace = true-serde_yaml.workspace = true+serde-saphyr = { workspace = true, features = ["deserialize", "serialize"] }tempfile.workspace = truejiff.workspace = truetar.workspace = truediff --git a/crates/ai-memory-wiki/src/error.rs b/crates/ai-memory-wiki/src/error.rsindex a2f83217..277a82be 100644--- a/crates/ai-memory-wiki/src/error.rs+++ b/crates/ai-memory-wiki/src/error.rs@@ -97,8 +97,8 @@ pub(crate) fn into_io_error(error: WikiError) -> std::io::Error {}}-impl From<serde_yaml::Error> for WikiError {- fn from(value: serde_yaml::Error) -> Self {+impl From<serde_saphyr::SerializeError> for WikiError {+ fn from(value: serde_saphyr::SerializeError) -> Self {Self::Yaml(value.to_string())}}diff --git a/crates/ai-memory-wiki/src/frontmatter_yaml.rs b/crates/ai-memory-wiki/src/frontmatter_yaml.rsnew file mode 100644index 00000000..38b70e9b--- /dev/null+++ b/crates/ai-memory-wiki/src/frontmatter_yaml.rs@@ -0,0 +1,397 @@+//! Frontmatter YAML to JSON, resolved the way `serde_yaml` 0.9 resolved it.+//!+//! This exists for parity with existing hand-edited pages: every page that+//! indexed under `serde_yaml` 0.9 must index to the same JSON now. The typed+//! `serde-saphyr` deserializer reads some plain scalars differently (`007`+//! and `1_000` as numbers, `.inf` as an error) and fails a page that uses+//! `!!timestamp`, so this walks the parser events of `serde-saphyr`'s own+//! YAML parser and ports `serde_yaml` 0.9's scalar rules. Frontmatter is+//! untrusted, so nesting stays capped at `serde_yaml`'s 128 containers and+//! alias expansion at a fixed node count.++use std::collections::{HashMap, HashSet};+use std::num::ParseIntError;++use serde_json::{Map, Number, Value};+use serde_saphyr::granit_parser::{Event, Parser, ScalarStyle, Span, StrInput, Tag};++/// `serde_yaml` 0.9's recursion limit, in nested sequences and mappings.+const MAX_DEPTH: usize = 128;+/// Nodes one frontmatter block may expand to, aliases included: the+/// alias-bomb guard (`serde-saphyr`'s default `max_nodes`).+const MAX_NODES: usize = 250_000;+const CORE_TAG_PREFIX: &str = "tag:yaml.org,2002:";++/// Parse one YAML document into JSON. Empty input is `Null`.+pub(crate) fn parse(input: &str) -> Result<Value, String> {+ let mut walker = Walker {+ input,+ parser: Parser::new_from_str(input),+ anchors: HashMap::new(),+ nodes: 0,+ };+ walker.document()+}++/// An anchored node, kept for its aliases with the cost of replaying it.+struct Anchored {+ value: Value,+ nodes: usize,+ height: usize,+}++struct Walker<'a> {+ input: &'a str,+ parser: Parser<'a, StrInput<'a>>,+ anchors: HashMap<usize, Anchored>,+ nodes: usize,+}++impl<'a> Walker<'a> {+ fn next(&mut self) -> Result<(Event<'a>, Span), String> {+ loop {+ match self.parser.next_event() {+ Some(Ok((Event::Comment(..), _))) => {}+ Some(Ok(event)) => return Ok(event),+ Some(Err(error)) => return Err(error.to_string()),+ None => return Err("unexpected end of YAML input".to_owned()),+ }+ }+ }++ fn document(&mut self) -> Result<Value, String> {+ let mut value = Value::Null;+ let mut documents = 0;+ loop {+ match self.next()? {+ (Event::StreamStart | Event::DocumentEnd, _) => {}+ (Event::StreamEnd, _) => return Ok(value),+ (Event::DocumentStart(..), span) => {+ documents += 1;+ if documents > 1 {+ return Err(format!(+ "more than one YAML document is not supported{}",+ at(span)+ ));+ }+ }+ (event, span) => value = self.node(event, span, 0)?.0,+ }+ }+ }++ /// Returns the node and its height in containers.+ fn node(+ &mut self,+ event: Event<'a>,+ span: Span,+ depth: usize,+ ) -> Result<(Value, usize), String> {+ let before = self.nodes;+ let (value, height, anchor, tag) = match event {+ Event::Alias(id) => {+ let anchored = self+ .anchors+ .get(&id)+ .ok_or_else(|| format!("unknown anchor{}", at(span)))?;+ if depth + anchored.height > MAX_DEPTH {+ return Err(format!("recursion limit exceeded{}", at(span)));+ }+ let (value, height, nodes) =+ (anchored.value.clone(), anchored.height, anchored.nodes);+ self.count(nodes, span)?;+ return Ok((value, height));+ }+ Event::Scalar(text, style, anchor, tag) => {+ self.count(1, span)?;+ let tag = tag_string(tag.as_deref());+ // A tagged value's content ignores the tag it was taken by.+ let own_tag = if enum_tag(&tag).is_some() {+ None+ } else {+ tag.as_deref()+ };+ let mut value =+ scalar(&text, style, own_tag).map_err(|e| format!("{e}{}", at(span)))?;+ // libyaml did not count a missing line break at the end of+ // input into a block scalar. Frontmatter always ends that way+ // (the fence drops the newline before `---`), so a block as+ // the last value lost its final newline under serde_yaml.+ if matches!(style, ScalarStyle::Literal | ScalarStyle::Folded)+ && span.end.byte_offset() == Some(self.input.len())+ && self.last_line_in_block(span)+ && let Value::String(text) = &mut value+ && text.ends_with('\n')+ {+ text.pop();+ }+ (value, 0, anchor, tag)+ }+ Event::SequenceStart(_, anchor, tag) => {+ self.enter(depth, span)?;+ let mut items = Vec::new();+ let mut height = 0;+ loop {+ match self.next()? {+ (Event::SequenceEnd, _) => break,+ (event, span) => {+ let (item, h) = self.node(event, span, depth + 1)?;+ height = height.max(h);+ items.push(item);+ }+ }+ }+ (+ Value::Array(items),+ height + 1,+ anchor,+ tag_string(tag.as_deref()),+ )+ }+ Event::MappingStart(_, anchor, tag) => {+ self.enter(depth, span)?;+ let mut map = Map::new();+ let mut seen = HashSet::new();+ let mut height = 0;+ loop {+ let (key, key_span) = match self.next()? {+ (Event::MappingEnd, _) => break,+ (event, span) => (self.node(event, span, depth + 1)?.0, span),+ };+ // serde_yaml compared keys as YAML values: `1` and `"1"`+ // are different keys there, though both land on "1".+ if !seen.insert(key.to_string()) {+ return Err(format!("duplicate entry with key {key}{}", at(key_span)));+ }+ let key = json_key(key).map_err(|e| format!("{e}{}", at(key_span)))?;+ let (event, span) = self.next()?;+ let (value, h) = self.node(event, span, depth + 1)?;+ height = height.max(h);+ map.insert(key, value);+ }+ (+ Value::Object(map),+ height + 1,+ anchor,+ tag_string(tag.as_deref()),+ )+ }+ _ => return Err(format!("unexpected YAML event{}", at(span))),+ };+ // A `!local` tag became a one-entry map in serde_yaml's JSON.+ let value = match enum_tag(&tag) {+ Some(name) => Value::Object(Map::from_iter([(name, value)])),+ None => value,+ };+ if anchor != 0 {+ let anchored = Anchored {+ value: value.clone(),+ nodes: self.nodes - before,+ height,+ };+ self.anchors.insert(anchor, anchored);+ }+ Ok((value, height))+ }++ /// Whether the input's unterminated last line belongs to the block+ /// scalar at `span`, whose span starts at its content indentation: any+ /// text does, and so does a blank line indented at least that deep.+ fn last_line_in_block(&self, span: Span) -> bool {+ match self.input.rsplit_once('\n') {+ Some((_, last)) if !last.is_empty() => {+ last.bytes().any(|b| b != b' ') || last.len() >= span.start.col()+ }+ _ => false,+ }+ }++ fn enter(&mut self, depth: usize, span: Span) -> Result<(), String> {+ self.count(1, span)?;+ if depth >= MAX_DEPTH {+ return Err(format!("recursion limit exceeded{}", at(span)));+ }+ Ok(())+ }++ fn count(&mut self, nodes: usize, span: Span) -> Result<(), String> {+ self.nodes = self.nodes.saturating_add(nodes);+ if self.nodes > MAX_NODES {+ return Err(format!(+ "frontmatter expands to more than {MAX_NODES} YAML nodes{}",+ at(span)+ ));+ }+ Ok(())+ }+}++/// The tag as libyaml spelled it: `!local`, or a resolved URI such as+/// `tag:yaml.org,2002:int` for `!!int`.+fn tag_string(tag: Option<&Tag>) -> Option<String> {+ tag.map(|tag| format!("{}{}", tag.handle(), tag.suffix()))+}++/// serde_yaml turned a tag starting with `!` into a tagged value, which its+/// JSON conversion wrote as `{"!name": value}`.+fn enum_tag(tag: &Option<String>) -> Option<String> {+ let tag = tag.as_deref()?;+ let rest = tag.strip_prefix('!')?;+ let name = if rest.is_empty() { tag } else { rest };+ let unbanged = match name.strip_prefix('!') {+ Some("") | None => name,+ Some(unbanged) => unbanged,+ };+ Some(format!("!{unbanged}"))+}++/// A key as serde_json's map-key serializer accepted it.+fn json_key(key: Value) -> Result<String, String> {+ match key {+ Value::String(s) => Ok(s),+ Value::Bool(b) => Ok(b.to_string()),+ Value::Number(n) => Ok(n.to_string()),+ _ => Err("key must be a string".to_owned()),+ }+}++/// `serde_yaml` 0.9's `visit_scalar`.+fn scalar(text: &str, style: ScalarStyle, tag: Option<&str>) -> Result<Value, String> {+ let core = tag.and_then(|t| t.strip_prefix(CORE_TAG_PREFIX));+ match core {+ Some("bool") => parse_bool(text)+ .map(Value::Bool)+ .ok_or_else(|| format!("invalid value: `{text}`, expected a boolean")),+ Some("int") => {+ int(text)?.ok_or_else(|| format!("invalid value: `{text}`, expected an integer"))+ }+ Some("float") => parse_f64(text)+ .map(float)+ .ok_or_else(|| format!("invalid value: `{text}`, expected a float")),+ Some("null") => parse_null(text)+ .then_some(Value::Null)+ .ok_or_else(|| format!("invalid value: `{text}`, expected null")),+ // Any other tag (`!!str`, `!!timestamp`, `!!binary`) keeps the text.+ _ if tag.is_none() && style == ScalarStyle::Plain => untagged(text),+ _ => Ok(Value::String(text.to_owned())),+ }+}++/// `serde_yaml` 0.9's `visit_untagged_scalar`.+fn untagged(text: &str) -> Result<Value, String> {+ if text.is_empty() || parse_null(text) {+ return Ok(Value::Null);+ }+ if let Some(b) = parse_bool(text) {+ return Ok(Value::Bool(b));+ }+ if let Some(int) = int(text)? {+ return Ok(int);+ }+ if !digits_but_not_number(text)+ && let Some(f) = parse_f64(text)+ {+ return Ok(float(f));+ }+ Ok(Value::String(text.to_owned()))+}++/// JSON has no infinity or NaN; serde_json wrote them as null.+fn float(f: f64) -> Value {+ Number::from_f64(f).map_or(Value::Null, Value::Number)+}++/// `serde_yaml` 0.9's `visit_int`. An integer wider than 64 bits was an+/// error there (`serde_yaml::Value` has no room for it), and stays one.+fn int(text: &str) -> Result<Option<Value>, String> {+ if let Some(u) = parse_unsigned_int(text, u64::from_str_radix) {+ return Ok(Some(Value::from(u)));+ }+ if let Some(i) = parse_negative_int(text, i64::from_str_radix) {+ return Ok(Some(Value::from(i)));+ }+ if parse_unsigned_int(text, u128::from_str_radix).is_some()+ || parse_negative_int(text, i128::from_str_radix).is_some()+ {+ return Err(format!("integer `{text}` does not fit in 64 bits"));+ }+ Ok(None)+}++fn parse_null(text: &str) -> bool {+ matches!(text, "null" | "Null" | "NULL" | "~")+}++fn parse_bool(text: &str) -> Option<bool> {+ match text {+ "true" | "True" | "TRUE" => Some(true),+ "false" | "False" | "FALSE" => Some(false),+ _ => None,+ }+}++type Radix<T> = fn(&str, u32) -> Result<T, ParseIntError>;++fn parse_unsigned_int<T>(text: &str, from_str_radix: Radix<T>) -> Option<T> {+ let unpositive = text.strip_prefix('+').unwrap_or(text);+ for (prefix, radix) in [("0x", 16), ("0o", 8), ("0b", 2)] {+ if let Some(rest) = unpositive.strip_prefix(prefix) {+ if rest.starts_with(['+', '-']) {+ return None;+ }+ if let Ok(int) = from_str_radix(rest, radix) {+ return Some(int);+ }+ }+ }+ if unpositive.starts_with(['+', '-']) || digits_but_not_number(text) {+ return None;+ }+ from_str_radix(unpositive, 10).ok()+}++fn parse_negative_int<T>(text: &str, from_str_radix: Radix<T>) -> Option<T> {+ for (prefix, radix) in [("-0x", 16), ("-0o", 8), ("-0b", 2)] {+ if let Some(rest) = text.strip_prefix(prefix)+ && let Ok(int) = from_str_radix(&format!("-{rest}"), radix)+ {+ return Some(int);+ }+ }+ if digits_but_not_number(text) {+ return None;+ }+ from_str_radix(text, 10).ok()+}++fn parse_f64(text: &str) -> Option<f64> {+ let unpositive = match text.strip_prefix('+') {+ Some(rest) if rest.starts_with(['+', '-']) => return None,+ Some(rest) => rest,+ None => text,+ };+ if let ".inf" | ".Inf" | ".INF" = unpositive {+ return Some(f64::INFINITY);+ }+ if let "-.inf" | "-.Inf" | "-.INF" = text {+ return Some(f64::NEG_INFINITY);+ }+ if let ".nan" | ".NaN" | ".NAN" = text {+ return Some(f64::NAN);+ }+ unpositive.parse::<f64>().ok().filter(|f| f.is_finite())+}++/// A leading zero followed by digits is a string in YAML 1.2.+fn digits_but_not_number(text: &str) -> bool {+ let text = text.strip_prefix(['-', '+']).unwrap_or(text);+ text.len() > 1 && text.starts_with('0') && text[1..].bytes().all(|b| b.is_ascii_digit())+}++fn at(span: Span) -> String {+ format!(+ " at line {} column {}",+ span.start.line(),+ span.start.col() + 1+ )+}diff --git a/crates/ai-memory-wiki/src/lib.rs b/crates/ai-memory-wiki/src/lib.rsindex 81b83cc7..e3e4cfb0 100644--- a/crates/ai-memory-wiki/src/lib.rs+++ b/crates/ai-memory-wiki/src/lib.rs@@ -10,6 +10,7 @@ mod atomic;pub mod backup;mod confinement;mod error;+mod frontmatter_yaml;mod git;mod ledger;mod markdown;diff --git a/crates/ai-memory-wiki/src/markdown.rs b/crates/ai-memory-wiki/src/markdown.rsindex a7d5fa87..e36386fb 100644--- a/crates/ai-memory-wiki/src/markdown.rs+++ b/crates/ai-memory-wiki/src/markdown.rs@@ -3,8 +3,8 @@//! We deliberately do *not* use `gray_matter` here: it parses fine but//! loses comments and key ordering on re-serialise, which is exactly the//! "duplicate frontmatter on already-frontmatter'd files" class of bug-//! basic-memory hit (#528). Going through `serde_yaml` directly keeps the-//! round-trip predictable.+//! basic-memory hit (#528). Reading through [`crate::frontmatter_yaml`] and+//! writing through `serde-saphyr` directly keeps the round-trip predictable.use std::collections::BTreeSet;use std::ops::Range;@@ -12,7 +12,23 @@ use std::ops::Range;use ai_memory_core::{DEFAULT_WORKSPACE_NAME, GLOBAL_SCOPE_PROJECT, LinkTarget, PagePath};use serde::{Deserialize, Serialize};-use crate::error::WikiResult;+use crate::error::{WikiError, WikiResult};++/// `yaml_12` emits plain scalars the way `serde_yaml` 0.9 did (no quotes+/// around dates or `yes`), but prefixes this header, which a frontmatter+/// block never carried.+const YAML_12_HEADER: &str = "%YAML 1.2\n---\n";++/// Serializer options for frontmatter, chosen to match `serde_yaml` 0.9+/// output. The one remaining difference: a value that needs quoting gets+/// double quotes where `serde_yaml` used single quotes.+fn frontmatter_emit_options() -> serde_saphyr::SerializerOptions {+ serde_saphyr::ser_options! {+ yaml_12: true,+ // Never fold long single-line strings into `>` blocks.+ folded_wrap_chars: usize::MAX,+ }+}/// A parsed markdown document with detached frontmatter.#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]@@ -58,8 +74,7 @@ pub fn parse(input: &str) -> WikiResult<Markdown> {{let fm_str = rest[..end].trim_end_matches('\r');let body = rest[end + close.len()..].to_string();- let fm_yaml: serde_yaml::Value = serde_yaml::from_str(fm_str)?;- let fm_json: serde_json::Value = serde_json::to_value(fm_yaml)?;+ let fm_json = crate::frontmatter_yaml::parse(fm_str).map_err(WikiError::Yaml)?;return Ok(Markdown {frontmatter: fm_json,body,@@ -72,7 +87,7 @@ pub fn parse(input: &str) -> WikiResult<Markdown> {}/// Emit a [`Markdown`] back to a string. Frontmatter is serialised through-/// `serde_yaml` (so it round-trips deterministically); a `Null` or empty+/// `serde-saphyr` (so it round-trips deterministically); a `Null` or empty/// object frontmatter is omitted entirely.////// # Errors@@ -85,9 +100,11 @@ pub fn emit(md: &Markdown) -> WikiResult<String> {};let mut out = String::with_capacity(md.body.len() + 32);if has_fm {- let yaml = serde_yaml::to_string(&md.frontmatter)?;+ let yaml =+ serde_saphyr::to_string_with_options(&md.frontmatter, frontmatter_emit_options())?;+ let yaml = yaml.strip_prefix(YAML_12_HEADER).unwrap_or(&yaml);out.push_str("---\n");- out.push_str(&yaml);+ out.push_str(yaml);if !yaml.ends_with('\n') {out.push('\n');}@@ -1301,6 +1318,245 @@ mod tests {assert_eq!(emit(&md).unwrap(), "Hello\n");}+ fn frontmatter_of(yaml: &str) -> serde_json::Value {+ parse(&format!("---\n{yaml}\n---\nbody\n"))+ .unwrap()+ .frontmatter+ }++ /// What `serde_yaml` 0.9 indexed for each value spelling (`None`: it+ /// refused the page). A hand-edited page must index the same now.+ #[test]+ fn frontmatter_values_match_serde_yaml_0_9() {+ use serde_json::json;+ let cases: &[(&str, Option<serde_json::Value>)] = &[+ // Leading zeros, digit separators, upper-case prefixes and+ // out-of-range floats were text.+ ("007", Some(json!("007"))),+ ("+08", Some(json!("+08"))),+ ("-01", Some(json!("-01"))),+ ("1_000", Some(json!("1_000"))),+ ("0X1F", Some(json!("0X1F"))),+ ("0O17", Some(json!("0O17"))),+ ("1e999", Some(json!("1e999"))),+ // Infinity and NaN have no JSON form; serde_json wrote null.+ (".inf", Some(json!(null))),+ ("-.inf", Some(json!(null))),+ (".nan", Some(json!(null))),+ ("+.nan", Some(json!("+.nan"))),+ // Integers wider than 64 bits were refused.+ ("18446744073709551616", None),+ ("-18446744073709551616", None),+ (+ "18446744073709551615",+ Some(json!(18_446_744_073_709_551_615_u64)),+ ),+ ("-9223372036854775808", Some(json!(i64::MIN))),+ // A local tag became a one-entry map; core tags kept the text.+ ("!foo bar", Some(json!({ "!foo": "bar" }))),+ ("!foo [1, 007]", Some(json!({ "!foo": [1, "007"] }))),+ ("!!timestamp 2026-10-12", Some(json!("2026-10-12"))),+ ("!!str 123", Some(json!("123"))),+ ("!!binary aGVsbG8=", Some(json!("aGVsbG8="))),+ // Controls.+ ("yes", Some(json!("yes"))),+ ("on", Some(json!("on"))),+ ("True", Some(json!(true))),+ ("2026-10-12", Some(json!("2026-10-12"))),+ ("2026-10-12T01:08:40Z", Some(json!("2026-10-12T01:08:40Z"))),+ ("0.92", Some(json!(0.92))),+ ("1e3", Some(json!(1000.0))),+ ("0x1F", Some(json!(31))),+ ("0o17", Some(json!(15))),+ ("0b101", Some(json!(5))),+ ("1:20", Some(json!("1:20"))),+ ("~", Some(json!(null))),+ ("", Some(json!(null))),+ ("'123'", Some(json!("123"))),+ ];+ for (yaml, expected) in cases {+ let parsed = parse(&format!("---\nv: {yaml}\n---\nbody\n"));+ match expected {+ Some(value) => assert_eq!(+ parsed.map(|md| md.frontmatter).ok(),+ Some(json!({ "v": value })),+ "v: {yaml}"+ ),+ None => assert!(+ matches!(parsed, Err(crate::error::WikiError::Yaml(_))),+ "v: {yaml} must be refused, got {parsed:?}"+ ),+ }+ }+ }++ #[test]+ fn last_block_scalar_drops_its_final_newline_as_serde_yaml_did() {+ // The fence drops the newline before `---`, so the YAML ends without+ // one; libyaml did not count the missing break into the block.+ let fm = frontmatter_of("a: |\n kept\nb: |\n last");+ assert_eq!(fm, serde_json::json!({ "a": "kept\n", "b": "last" }));+ let fm = frontmatter_of("b: |\n last\n ");+ assert_eq!(fm, serde_json::json!({ "b": "last\n" }));+ }++ #[test]+ fn empty_frontmatter_block_is_null() {+ let md = parse("---\n\n---\nbody\n").unwrap();+ assert!(md.frontmatter.is_null());+ assert_eq!(md.body, "body\n");+ }++ #[test]+ fn duplicate_frontmatter_keys_are_rejected() {+ let err = parse("---\ntitle: a\ntitle: b\n---\nbody\n").unwrap_err();+ let crate::error::WikiError::Yaml(msg) = err else {+ panic!("expected WikiError::Yaml, got {err:?}");+ };+ assert!(msg.contains("duplicate"), "{msg}");+ assert!(msg.contains("line 2"), "error names the location: {msg}");+ }++ #[test]+ fn block_scalars_and_multiline_strings_round_trip() {+ let fm =+ frontmatter_of("lit: |\n one\n two\nfold: >\n folded\n text\nstrip: |-\n keep");+ assert_eq!(+ fm,+ serde_json::json!({+ "lit": "one\ntwo\n",+ "fold": "folded text\n",+ "strip": "keep",+ })+ );+ let emitted = emit(&Markdown {+ frontmatter: fm.clone(),+ body: String::new(),+ })+ .unwrap();+ // serde_yaml 0.9 wrote newline-bearing strings as literal blocks.+ assert_eq!(+ emitted,+ "---\nlit: |\n one\n two\nfold: |\n folded text\nstrip: keep\n---\n"+ );+ assert_eq!(parse(&emitted).unwrap().frontmatter, fm);+ }++ #[test]+ fn keys_and_values_that_need_quotes_round_trip() {+ let fm = serde_json::json!({+ "key: colon": "a # b",+ "#hash": "@at",+ "123": "true",+ "": "null",+ "plain": "2026-10-12",+ });+ let emitted = emit(&Markdown {+ frontmatter: fm.clone(),+ body: String::new(),+ })+ .unwrap();+ // Quoting uses double quotes (serde_yaml 0.9 used single quotes);+ // dates stay plain, as serde_yaml wrote them.+ assert_eq!(+ emitted,+ "---\n\"key: colon\": \"a # b\"\n\"#hash\": \"@at\"\n\"123\": \"true\"\n\"\": \"null\"\nplain: 2026-10-12\n---\n"+ );+ assert_eq!(parse(&emitted).unwrap().frontmatter, fm);+ }++ #[test]+ fn non_ascii_and_long_strings_emit_plain_on_one_line() {+ let long = "word ".repeat(400).trim_end().to_string();+ let fm = serde_json::json!({ "title": "Olá — 日本語 🎉", "long": long });+ let emitted = emit(&Markdown {+ frontmatter: fm.clone(),+ body: String::new(),+ })+ .unwrap();+ assert_eq!(+ emitted,+ format!("---\ntitle: Olá — 日本語 🎉\nlong: {long}\n---\n")+ );+ assert_eq!(parse(&emitted).unwrap().frontmatter, fm);+ }++ /// A page in the shape serde_yaml 0.9 wrote (compact list indent, plain+ /// timestamps, `{}`/`[]` for empty collections) re-emits byte for byte,+ /// so the parser swap rewrites nothing on a page's next save.+ #[test]+ fn serde_yaml_shaped_page_re_emits_byte_for_byte() {+ let src = "---\n\+ kind: decision\n\+ confidence: 0.92\n\+ pinned: false\n\+ created_at: 2026-10-12T01:08:40Z\n\+ status: yes\n\+ tags:\n\+ - rust\n\+ - 日本語\n\+ summary: |\n First line.\n Second line.\n\+ evidence:\n\+ - kind: observation\n id: 019e5633-4140-7dd0-9e2f-118825ca6355\n at: 2026-07-18T09:35:52Z\n\+ - kind: page\n path: decisions/0001.md\n\+ relations: {}\n\+ aliases: []\n\+ ---\n\+ # Body\n";+ assert_eq!(emit(&parse(src).unwrap()).unwrap(), src);+ }++ #[test]+ fn frontmatter_alias_bomb_is_refused_quickly() {+ // Nine levels of nine-fold aliases expand to 9^9 nodes.+ let mut yaml = String::from("a: &a [x, x, x, x, x, x, x, x, x]\n");+ let mut prev = 'a';+ for name in "bcdefghi".chars() {+ let refs = vec![format!("*{prev}"); 9].join(", ");+ yaml.push_str(&format!("{name}: &{name} [{refs}]\n"));+ prev = name;+ }+ let started = std::time::Instant::now();+ let err = parse(&format!("---\n{yaml}---\nbody\n")).unwrap_err();+ assert!(+ matches!(err, crate::error::WikiError::Yaml(_)),+ "alias bomb must surface as a YAML error: {err:?}"+ );+ assert!(+ started.elapsed() < std::time::Duration::from_secs(5),+ "alias bomb refusal must stay bounded, took {:?}",+ started.elapsed()+ );++ // Control: ordinary anchors and aliases still parse, as before.+ let fm = frontmatter_of("base: &b\n tier: core\nref: *b\nlist: [*b]\nmerged:\n <<: *b");+ assert_eq!(+ fm,+ serde_json::json!({+ "base": { "tier": "core" },+ "ref": { "tier": "core" },+ "list": [{ "tier": "core" }],+ // serde_yaml 0.9 kept `<<` as an ordinary key.+ "merged": { "<<": { "tier": "core" } },+ })+ );+ }++ #[test]+ fn frontmatter_nesting_is_capped_at_serde_yaml_depth() {+ let nested = |depth: usize, inner: &str| {+ format!("{}{inner}{}", "[".repeat(depth), "]".repeat(depth))+ };+ // serde_yaml allowed 128 nested collections, the top mapping included.+ assert!(parse(&format!("---\nv: {}\n---\n", nested(127, "1"))).is_ok());+ let err = parse(&format!("---\nv: {}\n---\n", nested(128, "1"))).unwrap_err();+ assert!(matches!(err, crate::error::WikiError::Yaml(_)), "{err:?}");+ // An alias counts the depth it lands at, as serde_yaml's replay did.+ let deep_alias = format!("a: &a {}\nb: {}", nested(100, "1"), nested(30, "*a"));+ let err = parse(&format!("---\n{deep_alias}\n---\n")).unwrap_err();+ assert!(matches!(err, crate::error::WikiError::Yaml(_)), "{err:?}");+ }+#[test]fn title_priority_frontmatter_then_heading_then_stem() {let path = PagePath::new("notes/foo.md").unwrap();diff --git a/deny.toml b/deny.tomlindex 6355ef60..a9c939f4 100644--- a/deny.toml+++ b/deny.toml@@ -21,12 +21,6 @@ ignore = [# embeddings); no runtime code ships from it. Revisit when candle# replaces it upstream."RUSTSEC-2024-0436",- # RUSTSEC-2024-0449: `unsafe-libyaml` is unmaintained (no known- # vulnerability). It is the parser under `serde_yaml` 0.9, which reads- # and writes every wiki page's frontmatter. Replacing it changes how- # existing frontmatter serializes, so it needs its own change with a- # round-trip test over real pages, not a drive-by swap.- "RUSTSEC-2024-0449",][licenses]