Skip to content

Commit b112de8

Browse files
committed
fix: normalize CRLF to LF in agent file parser
On Windows, .lines() strips \n but keeps \r, causing byte offset miscalculation in frontmatter closing --- detection. The extracted YAML content gets corrupted and serde_yaml parsing fails silently. Normalize line endings before parsing to fix all 5 failing tests: - test_all_built_in_agents_parseable - test_explore_agent_disallows_write_tools - test_general_purpose_has_all_tools - test_scan_agents_no_dir - test_scan_agents_with_extra_dirs_dedup
1 parent 2ce72b4 commit b112de8

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

rust-agent-middlewares/src/claude_agent_parser.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ pub fn parse_agent_file(content: &str) -> Option<ClaudeAgent> {
162162

163163
/// 内部实现,返回具体错误信息
164164
fn parse_agent_file_inner(content: &str) -> Result<ClaudeAgent, String> {
165+
// Normalize line endings to LF to avoid CRLF-related byte offset issues on Windows.
166+
let content = content.replace("\r\n", "\n");
165167
let content = content.trim();
166168

167169
if !content.starts_with("---") {
@@ -180,7 +182,7 @@ fn parse_agent_file_inner(content: &str) -> Result<ClaudeAgent, String> {
180182
after_open
181183
.lines()
182184
.take(i + 1)
183-
.map(|l| l.len() + 1)
185+
.map(|l| l.len() + 1) // +1 for the '\n' stripped by .lines()
184186
.sum::<usize>()
185187
})
186188
.ok_or_else(|| "未找到闭合的 '---' 分隔符".to_string())?;

0 commit comments

Comments
 (0)