Address code review feedback for spawn-agent CLI

Co-authored-by: blackboxprogramming <118287761+blackboxprogramming@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-11-24 23:14:09 +00:00
parent 80379fee52
commit 0ccb161774
2 changed files with 12 additions and 9 deletions

View File

@@ -4,20 +4,23 @@ const path = require("path");
const agentName = process.argv[2]; const agentName = process.argv[2];
if (!agentName) { if (!agentName) {
console.error("❌ Please provide an agent name: `pnpm spawn-agent <agent-name>`"); console.error("❌ Please provide an agent name: `npm run spawn-agent <agent-name>`");
process.exit(1); process.exit(1);
} }
const toTitleCase = (str) => str.replace(/-/g, " ").replace(/\b\w/g, c => c.toUpperCase());
const agentId = agentName.toLowerCase().replace(/\s+/g, "-"); const agentId = agentName.toLowerCase().replace(/\s+/g, "-");
const displayName = toTitleCase(agentId);
const output = { const output = {
id: agentId, id: agentId,
name: agentName.replace(/-/g, " ").replace(/\b\w/g, c => c.toUpperCase()), name: displayName,
role: "worker", role: "worker",
traits: ["emoji-native"], traits: ["emoji-native"],
inputs: [], inputs: [],
outputs: [], outputs: [],
description: `This is the ${agentName} agent.`, description: `This is the ${displayName} agent.`,
triggers: [], triggers: [],
inherits_from: "base-agent" inherits_from: "base-agent"
}; };
@@ -32,13 +35,13 @@ const docPath = `docs/agents/${agentId}.mdx`;
fs.mkdirSync("agents", { recursive: true }); fs.mkdirSync("agents", { recursive: true });
fs.writeFileSync(jsonPath, JSON.stringify(output, null, 2)); fs.writeFileSync(jsonPath, JSON.stringify(output, null, 2));
fs.writeFileSync(promptPath, `SYSTEM:\nYou are the ${agentName} agent. Your job is to...`); fs.writeFileSync(promptPath, `SYSTEM:\nYou are the ${displayName} agent. Your job is to...`);
fs.mkdirSync(".github/workflows", { recursive: true }); fs.mkdirSync(".github/workflows", { recursive: true });
fs.writeFileSync(workflowPath, `name: ${agentName} Workflow\non:\n workflow_dispatch:\njobs:\n run:\n runs-on: ubuntu-latest\n steps:\n - run: echo "${agentName} agent triggered!"`); fs.writeFileSync(workflowPath, `name: ${displayName} Workflow\non:\n workflow_dispatch:\njobs:\n run:\n runs-on: ubuntu-latest\n steps:\n - run: echo "${displayName} agent triggered!"`);
fs.mkdirSync("docs/agents", { recursive: true }); fs.mkdirSync("docs/agents", { recursive: true });
fs.writeFileSync(docPath, `# ${agentName.replace(/-/g, " ").replace(/\b\w/g, c => c.toUpperCase())} Agent\n\nAuto-generated.\n\n## Purpose\nTBD`); fs.writeFileSync(docPath, `# ${displayName} Agent\n\nAuto-generated.\n\n## Purpose\nTBD`);
console.log(`✅ Created agent: ${agentId}`); console.log(`✅ Created agent: ${agentId}`);
console.log(`├─ ${jsonPath}`); console.log(`├─ ${jsonPath}`);

View File

@@ -42,7 +42,7 @@ describe("spawn-agent.js", () => {
]; ];
for (const d of dirs) { for (const d of dirs) {
if (fs.existsSync(d) && fs.readdirSync(d).length === 0) { if (fs.existsSync(d) && fs.readdirSync(d).length === 0) {
fs.rmdirSync(d); fs.rmSync(d, { recursive: true });
} }
} }
}); });
@@ -81,13 +81,13 @@ describe("spawn-agent.js", () => {
expect(fs.existsSync(promptPath)).toBe(true); expect(fs.existsSync(promptPath)).toBe(true);
const promptContent = fs.readFileSync(promptPath, "utf-8"); const promptContent = fs.readFileSync(promptPath, "utf-8");
expect(promptContent).toContain("SYSTEM:"); expect(promptContent).toContain("SYSTEM:");
expect(promptContent).toContain(TEST_AGENT_NAME); expect(promptContent).toContain("Test Agent Xyz");
// Check workflow file // Check workflow file
const workflowPath = path.join(ROOT_DIR, ".github", "workflows", `${TEST_AGENT_NAME}.workflow.yml`); const workflowPath = path.join(ROOT_DIR, ".github", "workflows", `${TEST_AGENT_NAME}.workflow.yml`);
expect(fs.existsSync(workflowPath)).toBe(true); expect(fs.existsSync(workflowPath)).toBe(true);
const workflowContent = fs.readFileSync(workflowPath, "utf-8"); const workflowContent = fs.readFileSync(workflowPath, "utf-8");
expect(workflowContent).toContain(`name: ${TEST_AGENT_NAME} Workflow`); expect(workflowContent).toContain("name: Test Agent Xyz Workflow");
expect(workflowContent).toContain("workflow_dispatch"); expect(workflowContent).toContain("workflow_dispatch");
// Check docs file // Check docs file