From 666bccbef63efba5120e9d4f49a7bdc0aa2c4e34 Mon Sep 17 00:00:00 2001 From: nayrosk <105997554+nayrosk@users.noreply.github.com> Date: Mon, 25 May 2026 20:12:38 +0200 Subject: [PATCH] fix(agents): strip markdown code spans from IDENTITY.md values and labels Refs #86594 --- src/agents/identity-file.test.ts | 20 ++++++++++++++++++++ src/agents/identity-file.ts | 6 +++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/agents/identity-file.test.ts b/src/agents/identity-file.test.ts index 30b3f2c70cd..be8437c7349 100644 --- a/src/agents/identity-file.test.ts +++ b/src/agents/identity-file.test.ts @@ -33,6 +33,26 @@ describe("parseIdentityMarkdown", () => { avatar: "avatars/openclaw.png", }); }); + + it("strips markdown code spans from values and labels", () => { + const content = [ + "- **Name:** `Samantha`", + "- `Creature`: Robot", + "- **`Avatar`**: `avatars/openclaw.png`", + ].join("\n"); + const parsed = parseIdentityMarkdown(content); + expect(parsed).toEqual({ + name: "Samantha", + creature: "Robot", + avatar: "avatars/openclaw.png", + }); + }); + + it("still treats code-span-wrapped template placeholders as placeholders", () => { + const content = "- **Avatar:** `(workspace-relative path, http(s) URL, or data URI)`"; + const parsed = parseIdentityMarkdown(content); + expect(parsed).toStrictEqual({}); + }); }); describe("mergeIdentityMarkdownContent", () => { diff --git a/src/agents/identity-file.ts b/src/agents/identity-file.ts index bcccd12e502..3915881d5f9 100644 --- a/src/agents/identity-file.ts +++ b/src/agents/identity-file.ts @@ -31,7 +31,7 @@ const IDENTITY_PLACEHOLDER_VALUES = new Set([ function normalizeIdentityValue(value: string): string { let normalized = value.trim(); - normalized = normalized.replace(/^[*_]+|[*_]+$/g, "").trim(); + normalized = normalized.replace(/^[*_`\s]+|[*_`\s]+$/g, "").trim(); if (normalized.startsWith("(") && normalized.endsWith(")")) { normalized = normalized.slice(1, -1).trim(); } @@ -54,11 +54,11 @@ export function parseIdentityMarkdown(content: string): AgentIdentityFile { continue; } const label = normalizeLowercaseStringOrEmpty( - cleaned.slice(0, colonIndex).replace(/[*_]/g, ""), + cleaned.slice(0, colonIndex).replace(/[*_`]/g, ""), ); const value = cleaned .slice(colonIndex + 1) - .replace(/^[*_]+|[*_]+$/g, "") + .replace(/^[*_`\s]+|[*_`\s]+$/g, "") .trim(); if (!value) { continue;