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
21 changes: 16 additions & 5 deletions src/specify_cli/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,24 @@ def parse_frontmatter(content: str) -> tuple[dict, str]:
if not content.startswith("---"):
return {}, content

# Find second ---
end_marker = content.find("---", 3)
if end_marker == -1:
# The closing delimiter is a line that is exactly ``---`` (a YAML
# document separator), not any ``---`` substring. Scanning with
# ``content.find("---", 3)`` stops at the first ``---`` *anywhere* —
# including one embedded in a frontmatter value (e.g. a description like
# "Separate sections with ---") or inside an indented literal block —
# which truncates the frontmatter and spills the remainder into the
# body. Match on line boundaries instead, mirroring the line-anchored
# scan in ``VibeIntegration._inject_frontmatter_flag``.
lines = content.splitlines(keepends=True)
end_line = next(
(i for i in range(1, len(lines)) if lines[i].rstrip() == "---"),
None,
)
if end_line is None:
return {}, content

frontmatter_str = content[3:end_marker].strip()
body = content[end_marker + 3 :].strip()
frontmatter_str = "".join(lines[1:end_line]).strip()
body = "".join(lines[end_line + 1 :]).strip()

try:
frontmatter = yaml.safe_load(frontmatter_str) or {}
Expand Down
15 changes: 15 additions & 0 deletions tests/test_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,21 @@ def test_parse_frontmatter_non_mapping_returns_empty_dict(self):
assert frontmatter == {}
assert "Command body" in body

def test_parse_frontmatter_dash_in_value(self):
"""A ``---`` inside a frontmatter value must not close the block early."""
content = """---
description: Separate sections with --- markers
argument-hint: "[name]"
---
Real body starts here.
"""
registrar = CommandRegistrar()
frontmatter, body = registrar.parse_frontmatter(content)

assert frontmatter["description"] == "Separate sections with --- markers"
assert frontmatter["argument-hint"] == "[name]"
assert body == "Real body starts here."

def test_render_frontmatter(self):
"""Test rendering frontmatter to YAML."""
frontmatter = {
Expand Down