fix(skill_engine): read block-scalar values in get_frontmatter_field

Line-oriented lookup returned the literal "|" for description: | blocks.
Delegate to parse_frontmatter so indented body lines are kept.
This commit is contained in:
santhreal 2026-07-18 18:57:59 -07:00
parent 2c5cc409b0
commit 87e7dcdd73
3 changed files with 22 additions and 9 deletions

1
.gitignore vendored
View file

@ -51,6 +51,7 @@ tests/skill_engine/*
!tests/skill_engine/test_evolver_length_recovery.py
!tests/skill_engine/test_evolution_retry_idempotency.py
!tests/skill_engine/test_analyzer_length_recovery.py
!tests/skill_engine/test_get_frontmatter_block_scalar.py
!tests/skill_engine/decision/
tests/skill_engine/decision/*
!tests/skill_engine/decision/test_analysis_adapter.py

View file

@ -113,18 +113,15 @@ def get_frontmatter_field(content: str, field_name: str) -> Optional[str]:
"""Extract a single field value from YAML frontmatter.
Returns ``None`` if the field is absent or content has no frontmatter.
Uses :func:`parse_frontmatter` so block scalars (``|`` / ``>``) round-trip.
"""
if not content.startswith("---"):
fm = parse_frontmatter(content)
if field_name not in fm:
return None
match = _FRONTMATTER_RE.match(content)
if not match:
value = fm[field_name]
if value is None:
return None
for line in match.group(1).split("\n"):
if ":" in line:
key, value = line.split(":", 1)
if key.strip() == field_name:
return _yaml_unquote(value.strip())
return None
return value if isinstance(value, str) else str(value)
def set_frontmatter_field(content: str, field_name: str, value: str) -> str:

View file

@ -0,0 +1,15 @@
"""Regression: get_frontmatter_field must read YAML block scalars."""
from __future__ import annotations
from openspace.skill_engine.skill_utils import get_frontmatter_field
def test_get_frontmatter_field_reads_block_scalar_description():
src = "---\nname: x\ndescription: |\n line1\n line2\n---\nbody\n"
assert get_frontmatter_field(src, "description") == "line1\nline2"
def test_get_frontmatter_field_missing_returns_none():
src = "---\nname: x\n---\n"
assert get_frontmatter_field(src, "description") is None