From da20e280f49f8fa2aa74166171e0c5322644581e Mon Sep 17 00:00:00 2001 From: Ramnique Singh <30795890+ramnique@users.noreply.github.com> Date: Thu, 18 Dec 2025 11:43:42 +0530 Subject: [PATCH] add migrate agents script --- apps/cli/package.json | 3 ++- apps/cli/src/agents/repo.ts | 4 +++- apps/cli/src/scripts/migrate-agents.ts | 23 +++++++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 apps/cli/src/scripts/migrate-agents.ts diff --git a/apps/cli/package.json b/apps/cli/package.json index d254a82d..95755a96 100644 --- a/apps/cli/package.json +++ b/apps/cli/package.json @@ -6,7 +6,8 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "build": "rm -rf dist && tsc", - "server": "node dist/server.js" + "server": "node dist/server.js", + "migrate-agents": "node dist/scripts/migrate-agents.js" }, "files": [ "dist", diff --git a/apps/cli/src/agents/repo.ts b/apps/cli/src/agents/repo.ts index 317beb0e..c770b1ee 100644 --- a/apps/cli/src/agents/repo.ts +++ b/apps/cli/src/agents/repo.ts @@ -77,7 +77,9 @@ export class FSAgentsRepo implements IAgentsRepo { } async create(agent: z.infer): Promise { - await fs.writeFile(path.join(this.agentsDir, `${agent.name}.md`), agent.instructions); + const { instructions, ...rest } = agent; + const contents = `---\n${stringify(rest)}\n---\n${instructions}`; + await fs.writeFile(path.join(this.agentsDir, `${agent.name}.md`), contents); } async update(id: string, agent: z.infer): Promise { diff --git a/apps/cli/src/scripts/migrate-agents.ts b/apps/cli/src/scripts/migrate-agents.ts new file mode 100644 index 00000000..93f66fcc --- /dev/null +++ b/apps/cli/src/scripts/migrate-agents.ts @@ -0,0 +1,23 @@ +import { Agent } from "../agents/agents.js"; +import { IAgentsRepo } from "../agents/repo.js"; +import { WorkDir } from "../config/config.js"; +import container from "../di/container.js"; +import { glob, readFile } from "node:fs/promises"; +import path from "path"; + +const main = async () => { + const agentsRepo = container.resolve("agentsRepo"); + const matches = await Array.fromAsync(glob("**/*.json", { cwd: path.join(WorkDir, "agents") })); + for (const file of matches) { + try { + const agent = Agent.parse(JSON.parse(await readFile(path.join(WorkDir, "agents", file), "utf8"))); + await agentsRepo.create(agent); + console.error(`migrated agent ${file}`); + } catch (error) { + console.error(`Error parsing agent ${file}: ${error instanceof Error ? error.message : String(error)}`); + continue; + } + } +} + +main(); \ No newline at end of file