Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(doctor): normalize CRLF in extractTriggers so Windows skill triggers parse (#1149)
samporter-312840734d702d
diff --git a/src/core/check-resolvable.ts b/src/core/check-resolvable.tsindex a82b4a2c10..9f2f729801 100644--- a/src/core/check-resolvable.ts+++ b/src/core/check-resolvable.ts@@ -217,9 +217,19 @@ export function parseResolverEntries(resolverContent: string): ResolverEntry[] {// `skillsDir/*/SKILL.md` when manifest.json is missing — the scenario// needed for AGENTS.md-only OpenClaw deployments. See D-CX-12 / F-ENG-1.-/** Simple YAML frontmatter parser — extracts triggers array if present. */-function extractTriggers(skillContent: string): string[] {- const fmMatch = skillContent.match(/^---\n([\s\S]*?)\n---/);+/**+ * Simple YAML frontmatter parser — extracts triggers array if present.+ *+ * Normalizes CRLF → LF before parsing so Windows checkouts (where+ * `core.autocrlf=true` is the default) parse correctly. Without this,+ * the `^---\n` and `^triggers:\s*\n` regexes never match because the+ * file content is `---\r\n` / `triggers:\r\n`, and every skill on+ * Windows is reported as `mece_gap` regardless of its actual content.+ * CI runs on Ubuntu-only so the bug only surfaces in user environments.+ */+export function extractTriggers(skillContent: string): string[] {+ const content = skillContent.replace(/\r\n/g, '\n');+ const fmMatch = content.match(/^---\n([\s\S]*?)\n---/);if (!fmMatch) return [];const fm = fmMatch[1];const triggersMatch = fm.match(/^triggers:\s*\n((?:\s+-\s+.+\n?)*)/m);diff --git a/test/check-resolvable.test.ts b/test/check-resolvable.test.tsindex 7e0c10e1ab..b26040b85b 100644--- a/test/check-resolvable.test.ts+++ b/test/check-resolvable.test.ts@@ -6,6 +6,7 @@ import {checkResolvable,parseResolverEntries,extractDelegationTargets,+ extractTriggers,} from "../src/core/check-resolvable.ts";const SKILLS_DIR = join(import.meta.dir, "..", "skills");@@ -195,6 +196,39 @@ describe("parseResolverEntries", () => {});});+describe("extractTriggers", () => {+ const LF_FRONTMATTER =+ "---\nname: query\ndescription: Test\ntriggers:\n - \"what do we know\"\n - \"tell me about\"\ntools:\n - search\n---\n\n# Body\n";++ test("parses triggers from LF-terminated frontmatter", () => {+ const triggers = extractTriggers(LF_FRONTMATTER);+ expect(triggers).toEqual(["what do we know", "tell me about"]);+ });++ test("parses triggers from CRLF-terminated frontmatter (Windows checkouts)", () => {+ // Regression: `core.autocrlf=true` is the Windows default. Without+ // CRLF→LF normalization, every Windows skill is reported as a false+ // mece_gap warning because the `^---\n` regex never matches `---\r\n`.+ const crlf = LF_FRONTMATTER.replace(/\n/g, "\r\n");+ const triggers = extractTriggers(crlf);+ expect(triggers).toEqual(["what do we know", "tell me about"]);+ });++ test("returns [] when frontmatter is missing", () => {+ expect(extractTriggers("# Just a body, no frontmatter\n")).toEqual([]);+ });++ test("returns [] when triggers field is absent from frontmatter", () => {+ const fm = "---\nname: query\ndescription: Test\ntools:\n - search\n---\n";+ expect(extractTriggers(fm)).toEqual([]);+ });++ test("strips surrounding quotes from trigger values", () => {+ const fm = "---\nname: x\ntriggers:\n - \"double quoted\"\n - 'single quoted'\n - unquoted\n---\n";+ expect(extractTriggers(fm)).toEqual(["double quoted", "single quoted", "unquoted"]);+ });+});+describe("checkResolvable — real skills directory", () => {const report = checkResolvable(SKILLS_DIR);