Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 17 additions & 5 deletions openspace/skill_engine/skill_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,29 @@ 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.
Block scalars (``|`` / ``>``) include following indented lines.
"""
if not content.startswith("---"):
return None
match = _FRONTMATTER_RE.match(content)
if not match:
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())
lines = match.group(1).split("\n")
for i, line in enumerate(lines):
if ":" not in line:
continue
key, value = line.split(":", 1)
if key.strip() != field_name:
continue
rest = value.strip()
if re.fullmatch(r"[|>][+-]?", rest):
collected: List[str] = []
j = i + 1
while j < len(lines) and lines[j].startswith((" ", "\t")):
collected.append(re.sub(r"^[ \t]+", "", lines[j], count=1))
j += 1
return "\n".join(collected)
return _yaml_unquote(rest)
return None


Expand Down
25 changes: 25 additions & 0 deletions tests/skill_engine/test_get_frontmatter_block_scalar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""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_reads_folded_scalar():
src = "---\nname: x\ndescription: >\n line1\n line2\n---\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


def test_get_frontmatter_field_keeps_plain_scalar_text():
src = "---\nenabled: true\n---\n"
assert get_frontmatter_field(src, "enabled") == "true"