





















@@ -31,14 +31,18 @@ const IDENTITY_PLACEHOLDER_VALUES = new Set([
31313232function normalizeIdentityValue(value: string): string {
3333let normalized = value.trim();
34-normalized = normalized.replace(/^[*_]+|[*_]+$/g, "").trim();
34+normalized = normalized.replace(/^[*_`\s]+|[*_`\s]+$/g, "").trim();
3535if (normalized.startsWith("(") && normalized.endsWith(")")) {
3636normalized = normalized.slice(1, -1).trim();
3737}
3838normalized = normalized.replace(/[\u2013\u2014]/g, "-");
3939return normalizeLowercaseStringOrEmpty(normalized.replace(/\s+/g, " "));
4040}
414142+function normalizeIdentityLabel(label: string): string {
43+return normalizeLowercaseStringOrEmpty(label.replace(/[*_`]/g, ""));
44+}
45+4246function isIdentityPlaceholder(value: string): boolean {
4347const normalized = normalizeIdentityValue(value);
4448return IDENTITY_PLACEHOLDER_VALUES.has(normalized);
@@ -53,12 +57,10 @@ export function parseIdentityMarkdown(content: string): AgentIdentityFile {
5357if (colonIndex === -1) {
5458continue;
5559}
56-const label = normalizeLowercaseStringOrEmpty(
57-cleaned.slice(0, colonIndex).replace(/[*_]/g, ""),
58-);
60+const label = normalizeIdentityLabel(cleaned.slice(0, colonIndex));
5961const value = cleaned
6062.slice(colonIndex + 1)
61-.replace(/^[*_]+|[*_]+$/g, "")
63+.replace(/^[*_`\s]+|[*_`\s]+$/g, "")
6264.trim();
6365if (!value) {
6466continue;
@@ -104,8 +106,16 @@ function buildIdentityLine(label: string, value: string): string {
104106}
105107106108function matchesIdentityLabel(line: string, label: string): boolean {
107-const escaped = label.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
108-return new RegExp(`^\\s*-\\s*(?:\\*\\*)?${escaped}(?:\\*\\*)?\\s*:`, "i").test(line.trim());
109+const trimmed = line.trim();
110+if (!trimmed.startsWith("-")) {
111+return false;
112+}
113+const cleaned = trimmed.replace(/^\s*-\s*/, "");
114+const colonIndex = cleaned.indexOf(":");
115+if (colonIndex === -1) {
116+return false;
117+}
118+return normalizeIdentityLabel(cleaned.slice(0, colonIndex)) === normalizeIdentityLabel(label);
109119}
110120111121function normalizeIdentityContent(content: string | undefined): string[] {
@@ -123,9 +133,7 @@ function resolveIdentityInsertIndex(lines: string[]): number {
123133if (colonIndex === -1) {
124134continue;
125135}
126-const label = normalizeLowercaseStringOrEmpty(
127-cleaned.slice(0, colonIndex).replace(/[*_]/g, ""),
128-);
136+const label = normalizeIdentityLabel(cleaned.slice(0, colonIndex));
129137if (RICH_IDENTITY_LABELS.has(label)) {
130138lastIdentityIndex = index;
131139}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。