feat: 9-agent migration matrix (dsh/workbuddy/zcode/mimo), 81 combinations tested, 210 tests
031fd6d verified Download src/migrator/generate.ts from hongcoding/agentlens: direct link, hf CLI and curl.
- Browser
- Download file 3.81 kB
-
https://huggingface.co/datasets/hongcoding/agentlens/resolve/main/src/migrator/generate.ts
- Command line
-
hf download hf://datasets/hongcoding/agentlens/src/migrator/generate.ts
-
curl -L -o generate.ts https://huggingface.co/datasets/hongcoding/agentlens/resolve/main/src/migrator/generate.ts
3.81 kB
| import type { Rule, AgentKind } from "../core/types.js"; | |
| /** | |
| * Generate agent-specific config file content from unified IR rules. | |
| */ | |
| export function generateConfig(rules: Rule[], target: AgentKind): string { | |
| switch (target) { | |
| case "claude": | |
| return generateClaude(rules); | |
| case "cursor": | |
| return generateCursor(rules); | |
| case "codex": | |
| return generateCodex(rules); | |
| case "windsurf": | |
| return generateWindsurf(rules); | |
| case "copilot": | |
| return generateCopilot(rules); | |
| case "dsh": | |
| case "workbuddy": | |
| case "zcode": | |
| case "mimo": | |
| // These agents all read the AGENTS.md standard (markdown instructions). | |
| return generateAgentsMd(rules); | |
| default: | |
| return generateGeneric(rules); | |
| } | |
| } | |
| function groupByCategory(rules: Rule[]): Map<string, Rule[]> { | |
| const groups = new Map<string, Rule[]>(); | |
| for (const rule of rules) { | |
| const key = rule.category; | |
| if (!groups.has(key)) groups.set(key, []); | |
| groups.get(key)!.push(rule); | |
| } | |
| return groups; | |
| } | |
| const CATEGORY_TITLES: Record<string, string> = { | |
| style: "Code Style", | |
| workflow: "Workflow", | |
| constraint: "Constraints", | |
| tooling: "Tools & Dependencies", | |
| context: "Project Context", | |
| }; | |
| function generateClaude(rules: Rule[]): string { | |
| const groups = groupByCategory(rules); | |
| const lines: string[] = ["# Project Rules\n"]; | |
| for (const [cat, items] of groups) { | |
| lines.push(`## ${CATEGORY_TITLES[cat] ?? cat}\n`); | |
| for (const r of items) { | |
| lines.push(`- ${r.content}`); | |
| } | |
| lines.push(""); | |
| } | |
| return lines.join("\n"); | |
| } | |
| function generateCursor(rules: Rule[]): string { | |
| // Output as .mdc format with frontmatter | |
| const groups = groupByCategory(rules); | |
| const lines: string[] = [ | |
| "---", | |
| "description: Migrated rules (generated by agentlens)", | |
| `globs: ["**/*"]`, | |
| "---", | |
| "", | |
| ]; | |
| for (const [cat, items] of groups) { | |
| lines.push(`## ${CATEGORY_TITLES[cat] ?? cat}\n`); | |
| for (const r of items) { | |
| lines.push(`- ${r.content}`); | |
| } | |
| lines.push(""); | |
| } | |
| return lines.join("\n"); | |
| } | |
| /** AGENTS.md standard — shared by Codex / DSH / WorkBuddy / ZCode / MiMo Desktop. */ | |
| function generateAgentsMd(rules: Rule[]): string { | |
| const groups = groupByCategory(rules); | |
| const lines: string[] = ["# Agent Instructions\n"]; | |
| for (const [cat, items] of groups) { | |
| lines.push(`## ${CATEGORY_TITLES[cat] ?? cat}\n`); | |
| for (const r of items) { | |
| lines.push(`- ${r.content}`); | |
| } | |
| lines.push(""); | |
| } | |
| return lines.join("\n"); | |
| } | |
| function generateCodex(rules: Rule[]): string { | |
| const groups = groupByCategory(rules); | |
| const lines: string[] = ["# Agent Instructions\n"]; | |
| for (const [cat, items] of groups) { | |
| lines.push(`## ${CATEGORY_TITLES[cat] ?? cat}\n`); | |
| for (const r of items) { | |
| lines.push(`- ${r.content}`); | |
| } | |
| lines.push(""); | |
| } | |
| return lines.join("\n"); | |
| } | |
| function generateWindsurf(rules: Rule[]): string { | |
| // .windsurfrules is plain markdown | |
| return generateClaude(rules); | |
| } | |
| function generateCopilot(rules: Rule[]): string { | |
| // .github/copilot-instructions.md is plain markdown | |
| return generateClaude(rules); | |
| } | |
| function generateGeneric(rules: Rule[]): string { | |
| return rules.map((r) => `- ${r.content}`).join("\n") + "\n"; | |
| } | |
| /** | |
| * Get the default output file path for a target agent. | |
| */ | |
| export function outputFileFor(target: AgentKind): string { | |
| switch (target) { | |
| case "claude": return "CLAUDE.md"; | |
| case "cursor": return ".cursor/rules/agentlens.mdc"; | |
| case "codex": return "AGENTS.md"; | |
| case "windsurf": return ".windsurfrules"; | |
| case "copilot": return ".github/copilot-instructions.md"; | |
| case "dsh": | |
| case "workbuddy": | |
| case "zcode": | |
| case "mimo": | |
| return "AGENTS.md"; | |
| default: return "agentlens-rules.md"; | |
| } | |
| } | |