fix(agents): strip markdown code spans from IDENTITY.md values and labels

Refs #86594
This commit is contained in:
nayrosk
2026-05-25 20:12:38 +02:00
committed by clawsweeper
parent 0d4575a241
commit 666bccbef6
2 changed files with 23 additions and 3 deletions

View File

@@ -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", () => {

View File

@@ -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;