Add `--to gemini` support for both `convert` and `install` commands, converting Claude Code plugins into Gemini CLI-compatible format. - Agents convert to `.gemini/skills/*/SKILL.md` with description frontmatter - Commands convert to `.gemini/commands/*.toml` with TOML prompt format - Namespaced commands create directory structure (workflows:plan -> workflows/plan.toml) - Skills pass through unchanged (identical SKILL.md standard) - MCP servers written to `.gemini/settings.json` with merge support - Content transforms: .claude/ paths, Task calls, @agent references - Hooks emit warning (different format in Gemini) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
343 lines
10 KiB
TypeScript
343 lines
10 KiB
TypeScript
import { describe, expect, test } from "bun:test"
|
|
import { convertClaudeToGemini, toToml, transformContentForGemini } from "../src/converters/claude-to-gemini"
|
|
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: {
|
|
local: { command: "echo", args: ["hello"] },
|
|
},
|
|
}
|
|
|
|
describe("convertClaudeToGemini", () => {
|
|
test("converts agents to skills with SKILL.md frontmatter", () => {
|
|
const bundle = convertClaudeToGemini(fixturePlugin, {
|
|
agentMode: "subagent",
|
|
inferTemperature: false,
|
|
permissions: "none",
|
|
})
|
|
|
|
const skill = bundle.generatedSkills.find((s) => s.name === "security-reviewer")
|
|
expect(skill).toBeDefined()
|
|
const parsed = parseFrontmatter(skill!.content)
|
|
expect(parsed.data.name).toBe("security-reviewer")
|
|
expect(parsed.data.description).toBe("Security-focused agent")
|
|
expect(parsed.body).toContain("Focus on vulnerabilities.")
|
|
})
|
|
|
|
test("agent with capabilities prepended to body", () => {
|
|
const bundle = convertClaudeToGemini(fixturePlugin, {
|
|
agentMode: "subagent",
|
|
inferTemperature: false,
|
|
permissions: "none",
|
|
})
|
|
|
|
const skill = bundle.generatedSkills.find((s) => s.name === "security-reviewer")
|
|
expect(skill).toBeDefined()
|
|
const parsed = parseFrontmatter(skill!.content)
|
|
expect(parsed.body).toContain("## Capabilities")
|
|
expect(parsed.body).toContain("- Threat modeling")
|
|
expect(parsed.body).toContain("- OWASP")
|
|
})
|
|
|
|
test("agent with empty description gets default description", () => {
|
|
const plugin: ClaudePlugin = {
|
|
...fixturePlugin,
|
|
agents: [
|
|
{
|
|
name: "my-agent",
|
|
body: "Do things.",
|
|
sourcePath: "/tmp/plugin/agents/my-agent.md",
|
|
},
|
|
],
|
|
commands: [],
|
|
skills: [],
|
|
}
|
|
|
|
const bundle = convertClaudeToGemini(plugin, {
|
|
agentMode: "subagent",
|
|
inferTemperature: false,
|
|
permissions: "none",
|
|
})
|
|
|
|
const parsed = parseFrontmatter(bundle.generatedSkills[0].content)
|
|
expect(parsed.data.description).toBe("Use this skill for my-agent tasks")
|
|
})
|
|
|
|
test("agent model field silently dropped", () => {
|
|
const bundle = convertClaudeToGemini(fixturePlugin, {
|
|
agentMode: "subagent",
|
|
inferTemperature: false,
|
|
permissions: "none",
|
|
})
|
|
|
|
const skill = bundle.generatedSkills.find((s) => s.name === "security-reviewer")
|
|
const parsed = parseFrontmatter(skill!.content)
|
|
expect(parsed.data.model).toBeUndefined()
|
|
})
|
|
|
|
test("agent with empty body gets default body text", () => {
|
|
const plugin: ClaudePlugin = {
|
|
...fixturePlugin,
|
|
agents: [
|
|
{
|
|
name: "Empty Agent",
|
|
description: "An empty agent",
|
|
body: "",
|
|
sourcePath: "/tmp/plugin/agents/empty.md",
|
|
},
|
|
],
|
|
commands: [],
|
|
skills: [],
|
|
}
|
|
|
|
const bundle = convertClaudeToGemini(plugin, {
|
|
agentMode: "subagent",
|
|
inferTemperature: false,
|
|
permissions: "none",
|
|
})
|
|
|
|
const parsed = parseFrontmatter(bundle.generatedSkills[0].content)
|
|
expect(parsed.body).toContain("Instructions converted from the Empty Agent agent.")
|
|
})
|
|
|
|
test("converts commands to TOML with prompt and description", () => {
|
|
const bundle = convertClaudeToGemini(fixturePlugin, {
|
|
agentMode: "subagent",
|
|
inferTemperature: false,
|
|
permissions: "none",
|
|
})
|
|
|
|
expect(bundle.commands).toHaveLength(1)
|
|
const command = bundle.commands[0]
|
|
expect(command.name).toBe("workflows/plan")
|
|
expect(command.content).toContain('description = "Planning command"')
|
|
expect(command.content).toContain('prompt = """')
|
|
expect(command.content).toContain("Plan the work.")
|
|
})
|
|
|
|
test("namespaced command creates correct path", () => {
|
|
const bundle = convertClaudeToGemini(fixturePlugin, {
|
|
agentMode: "subagent",
|
|
inferTemperature: false,
|
|
permissions: "none",
|
|
})
|
|
|
|
const command = bundle.commands.find((c) => c.name === "workflows/plan")
|
|
expect(command).toBeDefined()
|
|
})
|
|
|
|
test("command with argument-hint gets {{args}} placeholder", () => {
|
|
const bundle = convertClaudeToGemini(fixturePlugin, {
|
|
agentMode: "subagent",
|
|
inferTemperature: false,
|
|
permissions: "none",
|
|
})
|
|
|
|
const command = bundle.commands[0]
|
|
expect(command.content).toContain("{{args}}")
|
|
})
|
|
|
|
test("command with disable-model-invocation is still included", () => {
|
|
const plugin: ClaudePlugin = {
|
|
...fixturePlugin,
|
|
commands: [
|
|
{
|
|
name: "disabled-command",
|
|
description: "Disabled command",
|
|
disableModelInvocation: true,
|
|
body: "Disabled body.",
|
|
sourcePath: "/tmp/plugin/commands/disabled.md",
|
|
},
|
|
],
|
|
agents: [],
|
|
skills: [],
|
|
}
|
|
|
|
const bundle = convertClaudeToGemini(plugin, {
|
|
agentMode: "subagent",
|
|
inferTemperature: false,
|
|
permissions: "none",
|
|
})
|
|
|
|
// Gemini TOML commands are prompts, not code — always include
|
|
expect(bundle.commands).toHaveLength(1)
|
|
expect(bundle.commands[0].name).toBe("disabled-command")
|
|
})
|
|
|
|
test("command allowedTools silently dropped", () => {
|
|
const bundle = convertClaudeToGemini(fixturePlugin, {
|
|
agentMode: "subagent",
|
|
inferTemperature: false,
|
|
permissions: "none",
|
|
})
|
|
|
|
const command = bundle.commands[0]
|
|
expect(command.content).not.toContain("allowedTools")
|
|
expect(command.content).not.toContain("Read")
|
|
})
|
|
|
|
test("skills pass through as directory references", () => {
|
|
const bundle = convertClaudeToGemini(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("MCP servers convert to settings.json-compatible config", () => {
|
|
const bundle = convertClaudeToGemini(fixturePlugin, {
|
|
agentMode: "subagent",
|
|
inferTemperature: false,
|
|
permissions: "none",
|
|
})
|
|
|
|
expect(bundle.mcpServers?.local?.command).toBe("echo")
|
|
expect(bundle.mcpServers?.local?.args).toEqual(["hello"])
|
|
})
|
|
|
|
test("plugin with zero agents produces empty generatedSkills", () => {
|
|
const plugin: ClaudePlugin = {
|
|
...fixturePlugin,
|
|
agents: [],
|
|
commands: [],
|
|
skills: [],
|
|
}
|
|
|
|
const bundle = convertClaudeToGemini(plugin, {
|
|
agentMode: "subagent",
|
|
inferTemperature: false,
|
|
permissions: "none",
|
|
})
|
|
|
|
expect(bundle.generatedSkills).toHaveLength(0)
|
|
})
|
|
|
|
test("plugin with only skills works correctly", () => {
|
|
const plugin: ClaudePlugin = {
|
|
...fixturePlugin,
|
|
agents: [],
|
|
commands: [],
|
|
}
|
|
|
|
const bundle = convertClaudeToGemini(plugin, {
|
|
agentMode: "subagent",
|
|
inferTemperature: false,
|
|
permissions: "none",
|
|
})
|
|
|
|
expect(bundle.generatedSkills).toHaveLength(0)
|
|
expect(bundle.skillDirs).toHaveLength(1)
|
|
expect(bundle.commands).toHaveLength(0)
|
|
})
|
|
|
|
test("hooks present emits console.warn", () => {
|
|
const warnings: string[] = []
|
|
const originalWarn = console.warn
|
|
console.warn = (msg: string) => warnings.push(msg)
|
|
|
|
const plugin: ClaudePlugin = {
|
|
...fixturePlugin,
|
|
hooks: { hooks: { PreToolUse: [{ matcher: "*", body: "hook body" }] } },
|
|
agents: [],
|
|
commands: [],
|
|
skills: [],
|
|
}
|
|
|
|
convertClaudeToGemini(plugin, {
|
|
agentMode: "subagent",
|
|
inferTemperature: false,
|
|
permissions: "none",
|
|
})
|
|
|
|
console.warn = originalWarn
|
|
expect(warnings.some((w) => w.includes("Gemini"))).toBe(true)
|
|
})
|
|
})
|
|
|
|
describe("transformContentForGemini", () => {
|
|
test("transforms .claude/ paths to .gemini/", () => {
|
|
const result = transformContentForGemini("Read .claude/settings.json for config.")
|
|
expect(result).toContain(".gemini/settings.json")
|
|
expect(result).not.toContain(".claude/")
|
|
})
|
|
|
|
test("transforms ~/.claude/ paths to ~/.gemini/", () => {
|
|
const result = transformContentForGemini("Check ~/.claude/config for settings.")
|
|
expect(result).toContain("~/.gemini/config")
|
|
expect(result).not.toContain("~/.claude/")
|
|
})
|
|
|
|
test("transforms Task agent(args) to natural language skill reference", () => {
|
|
const input = `Run these:
|
|
|
|
- Task repo-research-analyst(feature_description)
|
|
- Task learnings-researcher(feature_description)
|
|
|
|
Task best-practices-researcher(topic)`
|
|
|
|
const result = transformContentForGemini(input)
|
|
expect(result).toContain("Use the repo-research-analyst skill to: feature_description")
|
|
expect(result).toContain("Use the learnings-researcher skill to: feature_description")
|
|
expect(result).toContain("Use the best-practices-researcher skill to: topic")
|
|
expect(result).not.toContain("Task repo-research-analyst")
|
|
})
|
|
|
|
test("transforms @agent references to skill references", () => {
|
|
const result = transformContentForGemini("Ask @security-sentinel for a review.")
|
|
expect(result).toContain("the security-sentinel skill")
|
|
expect(result).not.toContain("@security-sentinel")
|
|
})
|
|
})
|
|
|
|
describe("toToml", () => {
|
|
test("produces valid TOML with description and prompt", () => {
|
|
const result = toToml("A description", "The prompt content")
|
|
expect(result).toContain('description = "A description"')
|
|
expect(result).toContain('prompt = """')
|
|
expect(result).toContain("The prompt content")
|
|
expect(result).toContain('"""')
|
|
})
|
|
|
|
test("escapes quotes in description", () => {
|
|
const result = toToml('Say "hello"', "Prompt")
|
|
expect(result).toContain('description = "Say \\"hello\\""')
|
|
})
|
|
})
|