refactor(core): utilize normalizeContent in subagent, skill, and claude managers

This commit is contained in:
Aayush Yash 2026-02-21 18:23:57 +05:30
parent 93d86c0504
commit 7e0744b17c
4 changed files with 11 additions and 29 deletions

View file

@ -3,6 +3,7 @@ import * as fs from 'fs/promises';
import * as path from 'path';
import { parse as parseYaml } from '../utils/yaml-parser.js';
import { createDebugLogger } from '../utils/debugLogger.js';
import { normalizeContent } from '../utils/textUtils.js';
const debugLogger = createDebugLogger('SKILL_LOAD');
@ -56,21 +57,6 @@ export async function loadSkillsFromDir(
}
}
/**
* Normalizes skill file content for consistent parsing across platforms.
* - Strips UTF-8 BOM to ensure frontmatter starts at the first character.
* - Normalizes line endings so skills authored on Windows (CRLF) parse correctly.
*/
function normalizeSkillFileContent(content: string): string {
// Strip UTF-8 BOM to ensure frontmatter starts at the first character.
let normalized = content.replace(/^\uFEFF/, '');
// Normalize line endings so skills authored on Windows (CRLF) parse correctly.
normalized = normalized.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
return normalized;
}
export function parseSkillContent(
content: string,
filePath: string,
@ -78,7 +64,7 @@ export function parseSkillContent(
debugLogger.debug(`Parsing skill content from: ${filePath}`);
// Normalize content to handle BOM and CRLF line endings
const normalizedContent = normalizeSkillFileContent(content);
const normalizedContent = normalizeContent(content);
// Split frontmatter and content
// Use (?:\n|$) to allow frontmatter ending with or without trailing newline

View file

@ -20,6 +20,7 @@ import { SkillError, SkillErrorCode } from './types.js';
import type { Config } from '../config/config.js';
import { validateConfig } from './skill-load.js';
import { createDebugLogger } from '../utils/debugLogger.js';
import { normalizeContent } from '../utils/textUtils.js';
const debugLogger = createDebugLogger('SKILL_MANAGER');
@ -333,7 +334,7 @@ export class SkillManager {
level: SkillLevel,
): SkillConfig {
try {
const normalizedContent = normalizeSkillFileContent(content);
const normalizedContent = normalizeContent(content);
// Split frontmatter and content
const frontmatterRegex = /^---\n([\s\S]*?)\n---(?:\n|$)([\s\S]*)$/;
@ -649,13 +650,3 @@ export class SkillManager {
}
}
}
function normalizeSkillFileContent(content: string): string {
// Strip UTF-8 BOM to ensure frontmatter starts at the first character.
let normalized = content.replace(/^\uFEFF/, '');
// Normalize line endings so skills authored on Windows (CRLF) parse correctly.
normalized = normalized.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
return normalized;
}