Add Factory Droid as a converter target (#174)

Adds a new 'droid' target to the converter that outputs Claude Code plugins
in Factory Droid's format:

- Commands flattened to ~/.factory/commands/ (strips namespace prefixes)
- Agents converted to droids in ~/.factory/droids/ with proper frontmatter
- Skills copied to ~/.factory/skills/
- Content transforms: Task calls, slash commands, and @agent references
  adapted to Droid conventions

This resolves the manual workaround described in issue #31 by automating
the conversion from Claude Code plugin format to Factory Droid's expected
directory structure.

Includes 13 tests covering converter logic and file writer behavior.

Co-authored-by: adamprime <adamprime@hey.com>
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
Adam Tervort
2026-02-11 11:48:13 -06:00
committed by GitHub
parent e8f3bbcb35
commit 4ab08dce78
8 changed files with 648 additions and 10 deletions

View File

@@ -0,0 +1,277 @@
import { describe, expect, test } from "bun:test"
import { convertClaudeToDroid } from "../src/converters/claude-to-droid"
import { parseFrontmatter } from "../src/utils/frontmatter"
import type { ClaudePlugin } from "../src/types/claude"
const fixturePlugin: ClaudePlugin = {
root: "/tmp/plugin",
manifest: { name: "fixture", version: "1.0.0" },
agents: [
{
name: "Security Reviewer",
description: "Security-focused agent",
capabilities: ["Threat modeling", "OWASP"],
model: "claude-sonnet-4-20250514",
body: "Focus on vulnerabilities.",
sourcePath: "/tmp/plugin/agents/security-reviewer.md",
},
],
commands: [
{
name: "workflows:plan",
description: "Planning command",
argumentHint: "[FOCUS]",
model: "inherit",
allowedTools: ["Read"],
body: "Plan the work.",
sourcePath: "/tmp/plugin/commands/workflows/plan.md",
},
],
skills: [
{
name: "existing-skill",
description: "Existing skill",
sourceDir: "/tmp/plugin/skills/existing-skill",
skillPath: "/tmp/plugin/skills/existing-skill/SKILL.md",
},
],
hooks: undefined,
mcpServers: undefined,
}
describe("convertClaudeToDroid", () => {
test("flattens namespaced command names", () => {
const bundle = convertClaudeToDroid(fixturePlugin, {
agentMode: "subagent",
inferTemperature: false,
permissions: "none",
})
expect(bundle.commands).toHaveLength(1)
const command = bundle.commands[0]
expect(command.name).toBe("plan")
const parsed = parseFrontmatter(command.content)
expect(parsed.data.description).toBe("Planning command")
expect(parsed.data["argument-hint"]).toBe("[FOCUS]")
expect(parsed.body).toContain("Plan the work.")
})
test("converts agents to droids with frontmatter", () => {
const bundle = convertClaudeToDroid(fixturePlugin, {
agentMode: "subagent",
inferTemperature: false,
permissions: "none",
})
expect(bundle.droids).toHaveLength(1)
const droid = bundle.droids[0]
expect(droid.name).toBe("security-reviewer")
const parsed = parseFrontmatter(droid.content)
expect(parsed.data.name).toBe("security-reviewer")
expect(parsed.data.description).toBe("Security-focused agent")
expect(parsed.data.model).toBe("claude-sonnet-4-20250514")
expect(parsed.body).toContain("Capabilities")
expect(parsed.body).toContain("Threat modeling")
expect(parsed.body).toContain("Focus on vulnerabilities.")
})
test("passes through skill directories", () => {
const bundle = convertClaudeToDroid(fixturePlugin, {
agentMode: "subagent",
inferTemperature: false,
permissions: "none",
})
expect(bundle.skillDirs).toHaveLength(1)
expect(bundle.skillDirs[0].name).toBe("existing-skill")
expect(bundle.skillDirs[0].sourceDir).toBe("/tmp/plugin/skills/existing-skill")
})
test("sets model to inherit when not specified", () => {
const plugin: ClaudePlugin = {
...fixturePlugin,
agents: [
{
name: "basic-agent",
description: "Basic agent",
model: "inherit",
body: "Do things.",
sourcePath: "/tmp/plugin/agents/basic.md",
},
],
}
const bundle = convertClaudeToDroid(plugin, {
agentMode: "subagent",
inferTemperature: false,
permissions: "none",
})
const parsed = parseFrontmatter(bundle.droids[0].content)
expect(parsed.data.model).toBe("inherit")
})
test("transforms Task agent calls to droid-compatible syntax", () => {
const plugin: ClaudePlugin = {
...fixturePlugin,
commands: [
{
name: "plan",
description: "Planning with agents",
body: `Run these agents in parallel:
- Task repo-research-analyst(feature_description)
- Task learnings-researcher(feature_description)
Then consolidate findings.
Task best-practices-researcher(topic)`,
sourcePath: "/tmp/plugin/commands/plan.md",
},
],
agents: [],
skills: [],
}
const bundle = convertClaudeToDroid(plugin, {
agentMode: "subagent",
inferTemperature: false,
permissions: "none",
})
const parsed = parseFrontmatter(bundle.commands[0].content)
expect(parsed.body).toContain("Task repo-research-analyst: feature_description")
expect(parsed.body).toContain("Task learnings-researcher: feature_description")
expect(parsed.body).toContain("Task best-practices-researcher: topic")
expect(parsed.body).not.toContain("Task repo-research-analyst(")
})
test("transforms slash commands by flattening namespaces", () => {
const plugin: ClaudePlugin = {
...fixturePlugin,
commands: [
{
name: "plan",
description: "Planning with commands",
body: `After planning, you can:
1. Run /deepen-plan to enhance
2. Run /plan_review for feedback
3. Start /workflows:work to implement
Don't confuse with file paths like /tmp/output.md or /dev/null.`,
sourcePath: "/tmp/plugin/commands/plan.md",
},
],
agents: [],
skills: [],
}
const bundle = convertClaudeToDroid(plugin, {
agentMode: "subagent",
inferTemperature: false,
permissions: "none",
})
const parsed = parseFrontmatter(bundle.commands[0].content)
expect(parsed.body).toContain("/deepen-plan")
expect(parsed.body).toContain("/plan_review")
expect(parsed.body).toContain("/work")
expect(parsed.body).not.toContain("/workflows:work")
// File paths should NOT be transformed
expect(parsed.body).toContain("/tmp/output.md")
expect(parsed.body).toContain("/dev/null")
})
test("transforms @agent references to droid references", () => {
const plugin: ClaudePlugin = {
...fixturePlugin,
commands: [
{
name: "review",
description: "Review command",
body: "Have @agent-dhh-rails-reviewer and @agent-security-sentinel review the code.",
sourcePath: "/tmp/plugin/commands/review.md",
},
],
agents: [],
skills: [],
}
const bundle = convertClaudeToDroid(plugin, {
agentMode: "subagent",
inferTemperature: false,
permissions: "none",
})
const parsed = parseFrontmatter(bundle.commands[0].content)
expect(parsed.body).toContain("the dhh-rails-reviewer droid")
expect(parsed.body).toContain("the security-sentinel droid")
expect(parsed.body).not.toContain("@agent-")
})
test("preserves disable-model-invocation on commands", () => {
const plugin: ClaudePlugin = {
...fixturePlugin,
commands: [
{
name: "disabled-cmd",
description: "Disabled command",
disableModelInvocation: true,
body: "Body.",
sourcePath: "/tmp/plugin/commands/disabled.md",
},
],
agents: [],
skills: [],
}
const bundle = convertClaudeToDroid(plugin, {
agentMode: "subagent",
inferTemperature: false,
permissions: "none",
})
const parsed = parseFrontmatter(bundle.commands[0].content)
expect(parsed.data["disable-model-invocation"]).toBe(true)
})
test("handles multiple commands including nested and top-level", () => {
const plugin: ClaudePlugin = {
...fixturePlugin,
commands: [
{
name: "workflows:plan",
description: "Plan",
body: "Plan body.",
sourcePath: "/tmp/plugin/commands/workflows/plan.md",
},
{
name: "workflows:work",
description: "Work",
body: "Work body.",
sourcePath: "/tmp/plugin/commands/workflows/work.md",
},
{
name: "changelog",
description: "Changelog",
body: "Changelog body.",
sourcePath: "/tmp/plugin/commands/changelog.md",
},
],
agents: [],
skills: [],
}
const bundle = convertClaudeToDroid(plugin, {
agentMode: "subagent",
inferTemperature: false,
permissions: "none",
})
const names = bundle.commands.map((c) => c.name)
expect(names).toEqual(["plan", "work", "changelog"])
})
})

100
tests/droid-writer.test.ts Normal file
View File

@@ -0,0 +1,100 @@
import { describe, expect, test } from "bun:test"
import { promises as fs } from "fs"
import path from "path"
import os from "os"
import { writeDroidBundle } from "../src/targets/droid"
import type { DroidBundle } from "../src/types/droid"
async function exists(filePath: string): Promise<boolean> {
try {
await fs.access(filePath)
return true
} catch {
return false
}
}
describe("writeDroidBundle", () => {
test("writes commands, droids, and skills", async () => {
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "droid-test-"))
const bundle: DroidBundle = {
commands: [{ name: "plan", content: "Plan command content" }],
droids: [{ name: "security-reviewer", content: "Droid content" }],
skillDirs: [
{
name: "skill-one",
sourceDir: path.join(import.meta.dir, "fixtures", "sample-plugin", "skills", "skill-one"),
},
],
}
await writeDroidBundle(tempRoot, bundle)
expect(await exists(path.join(tempRoot, ".factory", "commands", "plan.md"))).toBe(true)
expect(await exists(path.join(tempRoot, ".factory", "droids", "security-reviewer.md"))).toBe(true)
expect(await exists(path.join(tempRoot, ".factory", "skills", "skill-one", "SKILL.md"))).toBe(true)
const commandContent = await fs.readFile(
path.join(tempRoot, ".factory", "commands", "plan.md"),
"utf8",
)
expect(commandContent).toContain("Plan command content")
const droidContent = await fs.readFile(
path.join(tempRoot, ".factory", "droids", "security-reviewer.md"),
"utf8",
)
expect(droidContent).toContain("Droid content")
})
test("writes directly into a .factory output root", async () => {
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "droid-home-"))
const factoryRoot = path.join(tempRoot, ".factory")
const bundle: DroidBundle = {
commands: [{ name: "plan", content: "Plan content" }],
droids: [{ name: "reviewer", content: "Reviewer content" }],
skillDirs: [],
}
await writeDroidBundle(factoryRoot, bundle)
expect(await exists(path.join(factoryRoot, "commands", "plan.md"))).toBe(true)
expect(await exists(path.join(factoryRoot, "droids", "reviewer.md"))).toBe(true)
// Should not double-nest under .factory/.factory
expect(await exists(path.join(factoryRoot, ".factory"))).toBe(false)
})
test("handles empty bundles gracefully", async () => {
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "droid-empty-"))
const bundle: DroidBundle = {
commands: [],
droids: [],
skillDirs: [],
}
await writeDroidBundle(tempRoot, bundle)
// Root should exist but no subdirectories created
expect(await exists(tempRoot)).toBe(true)
})
test("writes multiple commands as separate files", async () => {
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "droid-multi-"))
const factoryRoot = path.join(tempRoot, ".factory")
const bundle: DroidBundle = {
commands: [
{ name: "plan", content: "Plan content" },
{ name: "work", content: "Work content" },
{ name: "brainstorm", content: "Brainstorm content" },
],
droids: [],
skillDirs: [],
}
await writeDroidBundle(factoryRoot, bundle)
expect(await exists(path.join(factoryRoot, "commands", "plan.md"))).toBe(true)
expect(await exists(path.join(factoryRoot, "commands", "work.md"))).toBe(true)
expect(await exists(path.join(factoryRoot, "commands", "brainstorm.md"))).toBe(true)
})
})