Skip to content

Commit adbd1a9

Browse files
committed
fix: address second round of Copilot review feedback
1. Ensure .mdc frontmatter on existing files — upsert_context_section() now checks for missing YAML frontmatter on .mdc files during updates (not just creation), so pre-existing Cursor files get alwaysApply. 2. Guard against context_file=None — use 'or ""' instead of a default arg so explicit null values in init-options.json don't cause a TypeError in str.replace(). 3. Clean up .mdc files on removal — remove_context_section() treats files containing only the Speckit-generated frontmatter block as empty, deleting them rather than leaving orphaned frontmatter.
1 parent 9bb5ba3 commit adbd1a9

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/specify_cli/agents.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ def resolve_skill_placeholders(
364364
body = body.replace("{ARGS}", "$ARGUMENTS").replace("__AGENT__", agent_name)
365365

366366
# Resolve __CONTEXT_FILE__ from init-options
367-
context_file = init_opts.get("context_file", "")
367+
context_file = init_opts.get("context_file") or ""
368368
body = body.replace("__CONTEXT_FILE__", context_file)
369369

370370
return CommandRegistrar.rewrite_project_relative_paths(body)

src/specify_cli/integrations/base.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,10 @@ def upsert_context_section(
450450
new_content = content + "\n" + section
451451
else:
452452
new_content = section
453+
454+
# Ensure .mdc files have required YAML frontmatter
455+
if ctx_path.suffix == ".mdc" and not new_content.startswith("---\n"):
456+
new_content = "---\nalwaysApply: true\n---\n\n" + new_content
453457
else:
454458
ctx_path.parent.mkdir(parents=True, exist_ok=True)
455459
# Cursor .mdc files require YAML frontmatter to be loaded
@@ -497,6 +501,13 @@ def remove_context_section(self, project_root: Path) -> bool:
497501

498502
new_content = content[:start_idx] + content[end_of_marker:]
499503

504+
# For .mdc files, also strip Speckit-generated frontmatter
505+
if ctx_path.suffix == ".mdc":
506+
stripped = new_content.strip()
507+
if stripped in ("", "---\nalwaysApply: true\n---"):
508+
ctx_path.unlink()
509+
return True
510+
500511
if not new_content.strip():
501512
ctx_path.unlink()
502513
else:

0 commit comments

Comments
 (0)