Skip to content

Commit 1f19ab0

Browse files
committed
fix(claude): also skip unindented blank lines in description scalar
PyYAML serializes an embedded paragraph break ("\n\n") inside a quoted description as unindented blank lines, not indented continuation lines. inject_argument_hint only skipped indented lines, so it still inserted argument-hint mid-scalar for multi-paragraph descriptions, reproducing the github#4044 failure modes. Skip blank lines too, and add a regression test for the multi-paragraph case.
1 parent d748a86 commit 1f19ab0

2 files changed

Lines changed: 44 additions & 6 deletions

File tree

‎src/specify_cli/integrations/claude/__init__.py‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,13 @@ def inject_argument_hint(content: str, hint: str) -> str:
7070
"""Insert ``argument-hint`` after the ``description:`` scalar in YAML frontmatter.
7171
7272
A long ``description`` gets folded by the YAML dumper across
73-
indented continuation lines (plain or quoted). Inserting the new
74-
line right after the *first* line of that scalar — instead of after
75-
the whole scalar — either produces invalid YAML or gets silently
76-
absorbed into the description string (#4044), so every continuation
77-
line (anything more indented than the key itself) is skipped first.
73+
indented continuation lines (plain or quoted), and an embedded
74+
paragraph break can add unindented blank lines inside a quoted
75+
scalar. Inserting the new line right after the *first* line of
76+
that scalar — instead of after the whole scalar — either produces
77+
invalid YAML or gets silently absorbed into the description
78+
string (#4044), so every continuation line (indented, or blank)
79+
is skipped first.
7880
7981
Skips injection if ``argument-hint:`` already exists in the
8082
frontmatter to avoid duplicate keys.
@@ -113,7 +115,11 @@ def inject_argument_hint(content: str, hint: str) -> str:
113115
i += 1
114116
# Skip past folded/quoted continuation lines of the scalar
115117
# before inserting, so the new key lands after it ends.
116-
while i < n and lines[i][:1] in (" ", "\t"):
118+
# Blank lines count too: PyYAML emits unindented blank
119+
# lines for embedded "\n\n" inside a quoted scalar.
120+
while i < n and (
121+
lines[i][:1] in (" ", "\t") or lines[i].rstrip("\r\n") == ""
122+
):
117123
out.append(lines[i])
118124
i += 1
119125
# Preserve the exact line-ending style (\r\n vs \n)

‎tests/integrations/test_integration_claude.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,38 @@ def test_inject_argument_hint_survives_quoted_folded_description(self):
506506
assert parsed["argument-hint"] == "Describe the feature"
507507
assert parsed["description"] == frontmatter["description"]
508508

509+
def test_inject_argument_hint_survives_multi_paragraph_description(self):
510+
"""A description with an embedded blank line must not absorb the hint.
511+
512+
PyYAML serializes an embedded ``\\n\\n`` inside a quoted scalar as
513+
unindented blank lines, not indented ones, so a fix that only skips
514+
indented continuation lines still fails on this case.
515+
"""
516+
from specify_cli.integrations.claude import ClaudeIntegration
517+
518+
frontmatter = {
519+
"name": "speckit-specify",
520+
"description": (
521+
"First paragraph of a fairly long description that will "
522+
"need to wrap across multiple lines when dumped by PyYAML."
523+
"\n\n"
524+
"Second paragraph continues the description after a blank "
525+
"line separator to force embedded newlines in the scalar."
526+
),
527+
"compatibility": "Requires spec-kit project structure with .specify/ directory",
528+
}
529+
frontmatter_text = yaml.safe_dump(
530+
frontmatter, sort_keys=False, allow_unicode=True
531+
).strip()
532+
content = f"---\n{frontmatter_text}\n---\n\nBody text\n"
533+
assert "\n\n" in frontmatter_text, "fixture must produce a blank continuation line"
534+
535+
result = ClaudeIntegration.inject_argument_hint(content, "Describe the feature")
536+
537+
parsed = yaml.safe_load(result.split("---")[1])
538+
assert parsed["argument-hint"] == "Describe the feature"
539+
assert parsed["description"] == frontmatter["description"]
540+
509541

510542
class TestClaudeDisableModelInvocation:
511543
"""Verify disable-model-invocation is false for Claude skills."""

0 commit comments

Comments
 (0)