mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-30 15:50:24 +00:00
fix(agents): strip markdown code spans from IDENTITY.md values and labels
Refs #86594
This commit is contained in:
@@ -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", () => {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user