fix(core): allow Unicode characters in agent names (#3194)

The agent name validation regex only permitted ASCII letters, numbers,
hyphens, and underscores, silently rejecting agents with non-ASCII names
(e.g., Chinese "项目管理"). Replace the regex with Unicode property
escapes (\p{L}\p{N}) to allow letters and numbers from any script.

Also guard the lowercase naming convention warning so it only fires when
the name contains ASCII letters, since case is meaningless for CJK
scripts.

Fixes #3149
This commit is contained in:
tanzhenxin 2026-04-13 18:24:13 +08:00 committed by GitHub
parent 8d74a0cf0a
commit 34d560adcf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 4 deletions

View file

@ -22,6 +22,11 @@ describe('SubagentValidator', () => {
'code_reviewer',
'agent123',
'my-helper',
'项目管理',
'コードレビュー',
'코드리뷰',
'项目-manager',
'проект_менеджер',
];
for (const name of validNames) {
@ -120,6 +125,14 @@ describe('SubagentValidator', () => {
);
});
it('should not warn about case for non-Latin names', () => {
const result = validator.validateName('项目管理');
expect(result.isValid).toBe(true);
expect(result.warnings).not.toContain(
'Consider using lowercase names for consistency',
);
});
it('should warn about mixed separators', () => {
const result = validator.validateName('test-agent_helper');
expect(result.isValid).toBe(true);

View file

@ -116,8 +116,8 @@ export class SubagentValidator {
errors.push('Name must be 50 characters or less');
}
// Check valid characters (alphanumeric, hyphens, underscores)
const validNameRegex = /^[a-zA-Z0-9_-]+$/;
// Check valid characters (Unicode letters/numbers, hyphens, underscores)
const validNameRegex = /^[\p{L}\p{N}_-]+$/u;
if (!validNameRegex.test(trimmedName)) {
errors.push(
'Name can only contain letters, numbers, hyphens, and underscores',
@ -147,8 +147,11 @@ export class SubagentValidator {
errors.push(`"${trimmedName}" is a reserved name and cannot be used`);
}
// Warnings for naming conventions
if (trimmedName !== trimmedName.toLowerCase()) {
// Warnings for naming conventions (only for names that have case distinctions)
if (
trimmedName !== trimmedName.toLowerCase() &&
/[a-zA-Z]/.test(trimmedName)
) {
warnings.push('Consider using lowercase names for consistency');
}