Skip to content
Closed
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
94 changes: 94 additions & 0 deletions src/features/subagents/copilot-subagent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,81 @@ Plan tasks`;

expect(subagent.getFrontmatter().tools).toEqual(["agent/runSubagent"]);
});

it("converts .md extension to .agent.md in output file path", () => {
const rulesyncSubagent = new RulesyncSubagent({
baseDir: testDir,
relativeDirPath: RULESYNC_SUBAGENTS_RELATIVE_DIR_PATH,
relativeFilePath: "planner.md",
frontmatter: {
targets: ["copilot"],
name: "planner",
description: "Plan things",
copilot: {},
},
body: "Plan tasks",
validate: true,
});

const subagent = CopilotSubagent.fromRulesyncSubagent({
baseDir: testDir,
relativeDirPath: RULESYNC_SUBAGENTS_RELATIVE_DIR_PATH,
rulesyncSubagent,
validate: true,
}) as CopilotSubagent;

expect(subagent.getRelativeFilePath()).toBe("planner.agent.md");
});

it("preserves .agent.md extension when already present", () => {
const rulesyncSubagent = new RulesyncSubagent({
baseDir: testDir,
relativeDirPath: RULESYNC_SUBAGENTS_RELATIVE_DIR_PATH,
relativeFilePath: "planner.agent.md",
frontmatter: {
targets: ["copilot"],
name: "planner",
description: "Plan things",
copilot: {},
},
body: "Plan tasks",
validate: true,
});

const subagent = CopilotSubagent.fromRulesyncSubagent({
baseDir: testDir,
relativeDirPath: RULESYNC_SUBAGENTS_RELATIVE_DIR_PATH,
rulesyncSubagent,
validate: true,
}) as CopilotSubagent;

expect(subagent.getRelativeFilePath()).toBe("planner.agent.md");
});

it("throws when source file path does not end in .md", () => {
const rulesyncSubagent = new RulesyncSubagent({
baseDir: testDir,
relativeDirPath: RULESYNC_SUBAGENTS_RELATIVE_DIR_PATH,
relativeFilePath: "planner.txt",
frontmatter: {
targets: ["copilot"],
name: "planner",
description: "Plan things",
copilot: {},
},
body: "Plan tasks",
validate: true,
});

expect(() =>
CopilotSubagent.fromRulesyncSubagent({
baseDir: testDir,
relativeDirPath: RULESYNC_SUBAGENTS_RELATIVE_DIR_PATH,
rulesyncSubagent,
validate: true,
}),
).toThrow("Expected .md file path");
});
});

describe("toRulesyncSubagent", () => {
Expand Down Expand Up @@ -124,6 +199,25 @@ Plan tasks`;
});
expect(rulesyncSubagent.getBody()).toBe("Plan tasks");
});

it("converts .agent.md back to .md for rulesync file path", () => {
const subagent = new CopilotSubagent({
baseDir: testDir,
relativeDirPath: ".github/agents",
relativeFilePath: "planner.agent.md",
frontmatter: {
name: "planner",
description: "Plan things",
},
body: "Plan tasks",
fileContent: validContent,
validate: true,
});

const rulesyncSubagent = subagent.toRulesyncSubagent();

expect(rulesyncSubagent.getRelativeFilePath()).toBe("planner.md");
});
});

describe("fromFile", () => {
Expand Down
23 changes: 21 additions & 2 deletions src/features/subagents/copilot-subagent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ type CopilotSubagentParams = {
body: string;
} & AiFileParams;

const AGENT_MD_EXTENSION = ".agent.md";

const toAgentMdFilePath = (filePath: string): string => {
if (filePath.endsWith(AGENT_MD_EXTENSION)) {
return filePath;
}
if (filePath.endsWith(".md")) {
return filePath.slice(0, -3) + AGENT_MD_EXTENSION;
}
throw new Error(`Expected .md file path, got: ${filePath}`);
};

const fromAgentMdFilePath = (filePath: string): string => {
if (filePath.endsWith(AGENT_MD_EXTENSION)) {
return filePath.slice(0, -AGENT_MD_EXTENSION.length) + ".md";
}
return filePath;
};

const normalizeTools = (tools: string | string[] | undefined): string[] => {
if (!tools) {
return [];
Expand Down Expand Up @@ -98,7 +117,7 @@ export class CopilotSubagent extends ToolSubagent {
frontmatter: rulesyncFrontmatter,
body: this.body,
relativeDirPath: RULESYNC_SUBAGENTS_RELATIVE_DIR_PATH,
relativeFilePath: this.getRelativeFilePath(),
relativeFilePath: fromAgentMdFilePath(this.getRelativeFilePath()),
validate: true,
});
}
Expand Down Expand Up @@ -134,7 +153,7 @@ export class CopilotSubagent extends ToolSubagent {
frontmatter: copilotFrontmatter,
body,
relativeDirPath: paths.relativeDirPath,
relativeFilePath: rulesyncSubagent.getRelativeFilePath(),
relativeFilePath: toAgentMdFilePath(rulesyncSubagent.getRelativeFilePath()),
fileContent,
validate,
global,
Expand Down
2 changes: 1 addition & 1 deletion src/features/subagents/subagents-processor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ description: Copilot agent description
---
Copilot agent content`;

await writeFileContent(join(subagentsDir, "copilot-agent.md"), subagentContent);
await writeFileContent(join(subagentsDir, "copilot-agent.agent.md"), subagentContent);

const toolFiles = await processor.loadToolFiles();

Expand Down
2 changes: 1 addition & 1 deletion src/features/subagents/subagents-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const toolSubagentFactories = new Map<SubagentsProcessorToolTarget, ToolSubagent
"copilot",
{
class: CopilotSubagent,
meta: { supportsSimulated: false, supportsGlobal: false, filePattern: "*.md" },
meta: { supportsSimulated: false, supportsGlobal: false, filePattern: "*.agent.md" },
},
],
[
Expand Down
Loading