Fix identity emoji placeholder parsing

This commit is contained in:
xmanrui
2026-06-23 12:55:19 +08:00
parent b375fa5f90
commit e89408994f
2 changed files with 28 additions and 4 deletions
+22 -2
View File
@@ -13,6 +13,22 @@ const SUBAGENT_MAX_ACTIVE_MS = 10 * 60 * 1000
const SUBAGENT_ACTIVITY_EVENT_LIMIT = 6
const SUBAGENT_ACTIVITY_TEXT_MAX_LEN = 80
function normalizeIdentityValue(rawValue: string): string | null {
let value = rawValue.trim()
if (!value) return null
const placeholder = /^[_*`~\s]*\((?:your|pick|choose|fill|todo|tbd|||)[^)]*\)[_*`~\s]*/iu
while (placeholder.test(value)) {
value = value.replace(placeholder, '').replace(/^[-:,\s]+/, '').trim()
}
if (!value) return null
const wrapped = value.match(/^([_*`])(.+)\1$/)
if (wrapped) value = wrapped[2].trim()
return value || null
}
type SessionsIndex = Record<string, { sessionId?: string; updatedAt?: number }>
type CronStoreJob = {
id: string
@@ -996,8 +1012,12 @@ export async function GET() {
if (existsSync(identityPath)) {
try {
const identityRaw = await fs.readFile(identityPath, 'utf8')
const m = identityRaw.match(/\*\*Emoji:\*\*\s*(\S+)/)
if (m?.[1]) agentJsonEmoji = m[1]
const emojiLine = identityRaw.split(/\r?\n/).find((line) => /\*\*Emoji:\*\*/.test(line))
const m = emojiLine?.match(/\*\*Emoji:\*\*\s*(.*)$/)
if (m) {
const emoji = normalizeIdentityValue(m[1])
if (emoji) agentJsonEmoji = emoji
}
} catch { /* ignore */ }
}
}
+6 -2
View File
@@ -264,8 +264,12 @@ function readIdentityEmoji(agentId: string, agentDir?: string, workspace?: strin
for (const p of candidates) {
try {
const content = fs.readFileSync(p, "utf-8");
const match = content.match(/\*\*Emoji:\*\*\s*(\S+)/);
if (match?.[1]) return match[1].trim();
const emojiLine = content.split(/\r?\n/).find((line) => /\*\*Emoji:\*\*/.test(line));
const match = emojiLine?.match(/\*\*Emoji:\*\*\s*(.*)$/);
if (match) {
const emoji = normalizeIdentityName(match[1]);
if (emoji) return emoji;
}
} catch {}
}
return null;