fix(cli): treat full agent UUIDs as exact identifiers (#9680)

This commit is contained in:
ese111
2026-11-14 16:56:10 +00:00
committed by GitHub
parent b407990699
commit cec92d0be6
2 changed files with 38 additions and 4 deletions
+7
View File
@@ -236,6 +236,8 @@ interface AgentLike {
title?: string | null;
}
const FULL_AGENT_UUID_PATTERN = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i;
/**
* Resolve an agent ID from a partial ID or name.
* Supports:
@@ -252,6 +254,11 @@ export function resolveAgentId(idOrName: string, agents: AgentLike[]): string |
const query = idOrName.toLowerCase();
// A complete agent UUID is an exact identity, never a name search fallback.
if (FULL_AGENT_UUID_PATTERN.test(idOrName)) {
return agents.find((a) => a.id.toLowerCase() === query)?.id ?? null;
}
// Try exact ID match first
const exactMatch = agents.find((a) => a.id === idOrName);
if (exactMatch) {
@@ -18,25 +18,52 @@ const agents = [
}
{
console.log("Test 2: ID prefix resolves");
console.log("Test 2: full UUID resolves exactly, case-insensitively");
const exactId = "9eac296c-4d60-4189-a0b5-ae71dd9c6ad9";
const agentsWithNameCollision = [
{ id: exactId, title: "target agent" },
{
id: "c9a97e5d-4a92-4646-a016-53032146d0a1",
title: `worker ${exactId}`,
},
];
assert.strictEqual(resolveAgentId(exactId.toUpperCase(), agentsWithNameCollision), exactId);
console.log("✓ full UUID resolves exactly, case-insensitively\n");
}
{
console.log("Test 3: missing full UUID does not match another agent name");
const missingId = "9eac296c-4d60-4189-a0b5-ae71dd9c6ad9";
const nameCollision = [
{
id: "c9a97e5d-4a92-4646-a016-53032146d0a1",
title: `worker ${missingId}`,
},
];
assert.strictEqual(resolveAgentId(missingId, nameCollision), null);
console.log("✓ missing full UUID does not match another agent name\n");
}
{
console.log("Test 4: ID prefix resolves");
assert.strictEqual(resolveAgentId("def5678", agents), "def5678-other-agent-id");
console.log("✓ ID prefix resolves\n");
}
{
console.log("Test 3: exact name match resolves case-insensitively");
console.log("Test 5: exact name match resolves case-insensitively");
assert.strictEqual(resolveAgentId("fix archive flow", agents), "def5678-other-agent-id");
console.log("✓ exact name match resolves case-insensitively\n");
}
{
console.log("Test 4: partial name match resolves when unique");
console.log("Test 6: partial name match resolves when unique");
assert.strictEqual(resolveAgentId("review", agents), "987zyxw-third-agent-id");
console.log("✓ partial name match resolves when unique\n");
}
{
console.log("Test 5: missing agent returns null");
console.log("Test 7: missing agent returns null");
assert.strictEqual(resolveAgentId("does not exist", agents), null);
console.log("✓ missing agent returns null\n");
}