diff --git a/extensions/cli/src/services/AgentFileService.test.ts b/extensions/cli/src/services/AgentFileService.test.ts index 4914387e535..a87b6c7331e 100644 --- a/extensions/cli/src/services/AgentFileService.test.ts +++ b/extensions/cli/src/services/AgentFileService.test.ts @@ -739,7 +739,9 @@ You are a helpful agent`; ).rejects.toThrow("File not found"); }); - it("should throw error for non-markdown paths without trying file fallback", async () => { + it("should re-throw hub error for non-markdown hub slugs", async () => { + // Reset mock to clear any queued values from previous tests + mockLoadPackageFromHub.mockReset(); mockLoadPackageFromHub.mockRejectedValue(new Error("Hub error")); await expect( @@ -747,7 +749,7 @@ You are a helpful agent`; ).rejects.toThrow("Failed to load agent from owner/agent"); await expect( agentFileService.getAgentFile("owner/agent"), - ).rejects.toThrow("Not a markdown file"); + ).rejects.toThrow("Hub error"); }); it("should handle permission errors when reading files", async () => { diff --git a/extensions/cli/src/services/AgentFileService.ts b/extensions/cli/src/services/AgentFileService.ts index e03e8faf9af..e13078698f5 100644 --- a/extensions/cli/src/services/AgentFileService.ts +++ b/extensions/cli/src/services/AgentFileService.ts @@ -54,18 +54,27 @@ export class AgentFileService async getAgentFile(agentPath: string): Promise { try { + const isMarkdownPath = + agentPath.endsWith(".md") || agentPath.endsWith(".markdown"); + const parts = agentPath.split("/"); - if (parts.length === 2 && parts[0] && parts[1] && !parts.includes(".")) { + const looksLikeHubSlug = + parts.length === 2 && parts[0] && parts[1] && !parts.includes("."); + + if (looksLikeHubSlug) { try { return await loadPackageFromHub(agentPath, agentFileProcessor); - } catch { - // slug COULD be path, fall back to relative path + } catch (hubError) { + // Hub loading failed - only fall back to file if it's a markdown path + if (!isMarkdownPath) { + // Not a markdown path, so re-throw the hub error + throw hubError; + } + // It's a markdown path, fall through to try loading as file } } - const isMarkdownPath = - agentPath.endsWith(".md") || agentPath.endsWith(".markdown"); - // Only fall back to relative path for markdown files + // Only load from file path for markdown files if (!isMarkdownPath) { throw new Error( `Failed to load agent from ${agentPath}. Not a markdown file`,