Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions extensions/cli/src/services/AgentFileService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,15 +739,17 @@ 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(
agentFileService.getAgentFile("owner/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 () => {
Expand Down
21 changes: 15 additions & 6 deletions extensions/cli/src/services/AgentFileService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,27 @@ export class AgentFileService

async getAgentFile(agentPath: string): Promise<AgentFile> {
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`,
Expand Down
Loading