Skip to content

Commit f227ab6

Browse files
fsilvaortizclaude
andcommitted
refactor: address Copilot review suggestions
- Handle CRLF line endings in frontmatter detection (grep '^---' instead of '^---$') - Fix double blank line after frontmatter in PowerShell New-AgentFile - Remove unused tempfile import from tests - Add encoding="utf-8" to all open() calls for cross-platform safety Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 547fd50 commit f227ab6

3 files changed

Lines changed: 5 additions & 6 deletions

File tree

scripts/bash/update-agent-context.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ update_existing_agent_file() {
503503

504504
# Ensure Cursor .mdc files have YAML frontmatter for auto-inclusion
505505
if [[ "$target_file" == *.mdc ]]; then
506-
if ! head -1 "$temp_file" | grep -q '^---$'; then
506+
if ! head -1 "$temp_file" | grep -q '^---'; then
507507
local frontmatter_file
508508
frontmatter_file=$(mktemp) || { rm -f "$temp_file"; return 1; }
509509
printf '%s\n' "---" "description: Project Development Guidelines" "globs: [\"**/*\"]" "alwaysApply: true" "---" "" > "$frontmatter_file"

scripts/powershell/update-agent-context.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ function New-AgentFile {
261261
# Prepend Cursor frontmatter for .mdc files so rules are auto-included
262262
if ($TargetFile -match '\.mdc$') {
263263
$frontmatter = @('---','description: Project Development Guidelines','globs: ["**/*"]','alwaysApply: true','---','') -join [Environment]::NewLine
264-
$content = $frontmatter + [Environment]::NewLine + $content
264+
$content = $frontmatter + $content
265265
}
266266

267267
$parent = Split-Path -Parent $TargetFile

tests/test_cursor_frontmatter.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import os
99
import shutil
1010
import subprocess
11-
import tempfile
1211
import textwrap
1312

1413
import pytest
@@ -40,14 +39,14 @@ class TestScriptFrontmatterPattern:
4039

4140
def test_create_new_has_mdc_frontmatter_logic(self):
4241
"""create_new_agent_file() must contain .mdc frontmatter logic."""
43-
with open(SCRIPT_PATH) as f:
42+
with open(SCRIPT_PATH, encoding="utf-8") as f:
4443
content = f.read()
4544
assert 'if [[ "$target_file" == *.mdc ]]' in content
4645
assert "alwaysApply: true" in content
4746

4847
def test_update_existing_has_mdc_frontmatter_logic(self):
4948
"""update_existing_agent_file() must also handle .mdc frontmatter."""
50-
with open(SCRIPT_PATH) as f:
49+
with open(SCRIPT_PATH, encoding="utf-8") as f:
5150
content = f.read()
5251
# There should be two occurrences of the .mdc check — one per function
5352
occurrences = content.count('if [[ "$target_file" == *.mdc ]]')
@@ -64,7 +63,7 @@ def test_powershell_script_has_mdc_frontmatter_logic(self):
6463
"powershell",
6564
"update-agent-context.ps1",
6665
)
67-
with open(ps_path) as f:
66+
with open(ps_path, encoding="utf-8") as f:
6867
content = f.read()
6968
assert "alwaysApply: true" in content
7069
occurrences = content.count(r"\.mdc$")

0 commit comments

Comments
 (0)