Skip to content

Commit 03af8ec

Browse files
committed
fix: remove unused MDC_FRONTMATTER, preserve inline comments, normalize bare CR
1. Remove unused MDC_FRONTMATTER class variable — dead code after _ensure_mdc_frontmatter() was rewritten with regex. 2. Preserve inline comments when fixing alwaysApply — the regex substitution now captures trailing '# comment' text and keeps it. 3. Normalize bare CR in upsert_context_section() — match the behavior of remove_context_section() which already normalizes both CRLF and bare CR. 4. Clarify .mdc removal comment — 'treat frontmatter-only as empty' instead of misleading 'strip frontmatter'.
1 parent 841bcd8 commit 03af8ec

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

  • src/specify_cli/integrations

src/specify_cli/integrations/base.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,6 @@ def install_scripts(
387387

388388
# -- Agent context file management ------------------------------------
389389

390-
MDC_FRONTMATTER = "---\nalwaysApply: true\n---"
391-
392390
@staticmethod
393391
def _ensure_mdc_frontmatter(content: str) -> str:
394392
"""Ensure ``.mdc`` content has YAML frontmatter with ``alwaysApply: true``.
@@ -426,11 +424,12 @@ def _ensure_mdc_frontmatter(content: str) -> str:
426424
):
427425
return content
428426

429-
# alwaysApply exists but wrong value — fix in place
427+
# alwaysApply exists but wrong value — fix in place while preserving
428+
# indentation and any trailing inline comment.
430429
if _re.search(r"(?m)^[ \t]*alwaysApply[ \t]*:", fm_text):
431430
fm_text = _re.sub(
432-
r"(?m)^([ \t]*)alwaysApply[ \t]*:.*$",
433-
r"\1alwaysApply: true",
431+
r"(?m)^([ \t]*)alwaysApply[ \t]*:.*?([ \t]*(?:#.*)?)$",
432+
r"\1alwaysApply: true\2",
434433
fm_text,
435434
count=1,
436435
)
@@ -525,7 +524,7 @@ def upsert_context_section(
525524
else:
526525
new_content = section
527526

528-
normalized = new_content.replace("\r\n", "\n")
527+
normalized = new_content.replace("\r\n", "\n").replace("\r", "\n")
529528
ctx_path.write_bytes(normalized.encode("utf-8"))
530529
return ctx_path
531530

@@ -567,10 +566,10 @@ def remove_context_section(self, project_root: Path) -> bool:
567566
# Normalize line endings before comparisons
568567
normalized = new_content.replace("\r\n", "\n").replace("\r", "\n")
569568

570-
# For .mdc files, also strip Speckit-generated frontmatter
569+
# For .mdc files, treat Speckit-generated frontmatter-only content as empty
571570
if ctx_path.suffix == ".mdc":
572571
import re
573-
# Treat as empty if only YAML frontmatter remains (no body content)
572+
# Delete the file if only YAML frontmatter remains (no body content)
574573
frontmatter_only = re.match(
575574
r"^---\n.*?\n---\s*$", normalized, re.DOTALL
576575
)

0 commit comments

Comments
 (0)