Files
claude-engineering-plugin/tests/converter.test.ts
Kieran Klaassen f744b797ef Reduce context token usage by 79% — fix silent component exclusion (#161)
* Update create-agent-skills to match 2026 official docs, add /triage-prs command

- Rewrite SKILL.md to document that commands and skills are now merged
- Add new frontmatter fields: disable-model-invocation, user-invocable, context, agent
- Add invocation control table and dynamic context injection docs
- Fix skill-structure.md: was incorrectly recommending XML tags over markdown headings
- Update official-spec.md with complete 2026 specification
- Add local /triage-prs command for PR triage workflow
- Add PR triage plan document

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* [2.31.0] Reduce context token usage by 79%, include recent community contributions

The plugin was consuming 316% of Claude Code's description character budget
(~50,500 chars vs 16,000 limit), causing components to be silently excluded.
Now at 65% (~10,400 chars) with all components visible.

Changes:
- Trim all 29 agent descriptions (move examples to body)
- Add disable-model-invocation to 18 manual commands
- Add disable-model-invocation to 6 manual skills
- Include recent community contributions in changelog
- Fix component counts (29 agents, 24 commands, 18 skills)

Contributors: @trevin, @terryli, @robertomello, @zacwilliams,
@aarnikoskela, @samxie, @davidalley

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix: keep disable-model-invocation off commands called by /lfg, rename xcode-test

- Remove disable-model-invocation from test-browser, feature-video,
  resolve_todo_parallel — these are called programmatically by /lfg and /slfg
- Rename xcode-test to test-xcode to match test-browser naming convention

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix: keep git-worktree skill auto-invocable (used by /workflows:work)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat(converter): support disable-model-invocation frontmatter

Parse disable-model-invocation from command and skill frontmatter.
Commands/skills with this flag are excluded from OpenCode command maps
and Codex prompt/skill generation, matching Claude Code behavior where
these components are user-only invocable.

Bump converter version to 0.3.0.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-08 22:28:51 -06:00

187 lines
6.4 KiB
TypeScript

import { describe, expect, test } from "bun:test"
import path from "path"
import { loadClaudePlugin } from "../src/parsers/claude"
import { convertClaudeToOpenCode } from "../src/converters/claude-to-opencode"
import { parseFrontmatter } from "../src/utils/frontmatter"
const fixtureRoot = path.join(import.meta.dir, "fixtures", "sample-plugin")
describe("convertClaudeToOpenCode", () => {
test("maps commands, permissions, and agents", async () => {
const plugin = await loadClaudePlugin(fixtureRoot)
const bundle = convertClaudeToOpenCode(plugin, {
agentMode: "subagent",
inferTemperature: false,
permissions: "from-commands",
})
expect(bundle.config.command?.["workflows:review"]).toBeDefined()
expect(bundle.config.command?.["plan_review"]).toBeDefined()
const permission = bundle.config.permission as Record<string, string | Record<string, string>>
expect(Object.keys(permission).sort()).toEqual([
"bash",
"edit",
"glob",
"grep",
"list",
"patch",
"question",
"read",
"skill",
"task",
"todoread",
"todowrite",
"webfetch",
"write",
])
expect(permission.edit).toBe("allow")
expect(permission.write).toBe("allow")
const bashPermission = permission.bash as Record<string, string>
expect(bashPermission["ls *"]).toBe("allow")
expect(bashPermission["git *"]).toBe("allow")
expect(permission.webfetch).toBe("allow")
const readPermission = permission.read as Record<string, string>
expect(readPermission["*"]).toBe("deny")
expect(readPermission[".env"]).toBe("allow")
expect(permission.question).toBe("allow")
expect(permission.todowrite).toBe("allow")
expect(permission.todoread).toBe("allow")
const agentFile = bundle.agents.find((agent) => agent.name === "repo-research-analyst")
expect(agentFile).toBeDefined()
const parsed = parseFrontmatter(agentFile!.content)
expect(parsed.data.mode).toBe("subagent")
})
test("normalizes models and infers temperature", async () => {
const plugin = await loadClaudePlugin(fixtureRoot)
const bundle = convertClaudeToOpenCode(plugin, {
agentMode: "subagent",
inferTemperature: true,
permissions: "none",
})
const securityAgent = bundle.agents.find((agent) => agent.name === "security-sentinel")
expect(securityAgent).toBeDefined()
const parsed = parseFrontmatter(securityAgent!.content)
expect(parsed.data.model).toBe("anthropic/claude-sonnet-4-20250514")
expect(parsed.data.temperature).toBe(0.1)
const modelCommand = bundle.config.command?.["workflows:work"]
expect(modelCommand?.model).toBe("openai/gpt-4o")
})
test("converts hooks into plugin file", async () => {
const plugin = await loadClaudePlugin(fixtureRoot)
const bundle = convertClaudeToOpenCode(plugin, {
agentMode: "subagent",
inferTemperature: false,
permissions: "none",
})
const hookFile = bundle.plugins.find((file) => file.name === "converted-hooks.ts")
expect(hookFile).toBeDefined()
expect(hookFile!.content).toContain("\"tool.execute.before\"")
expect(hookFile!.content).toContain("\"tool.execute.after\"")
expect(hookFile!.content).toContain("\"session.created\"")
expect(hookFile!.content).toContain("\"session.deleted\"")
expect(hookFile!.content).toContain("\"session.idle\"")
expect(hookFile!.content).toContain("\"experimental.session.compacting\"")
expect(hookFile!.content).toContain("\"permission.requested\"")
expect(hookFile!.content).toContain("\"permission.replied\"")
expect(hookFile!.content).toContain("\"message.created\"")
expect(hookFile!.content).toContain("\"message.updated\"")
expect(hookFile!.content).toContain("echo before")
expect(hookFile!.content).toContain("echo before two")
expect(hookFile!.content).toContain("// timeout: 30s")
expect(hookFile!.content).toContain("// Prompt hook for Write|Edit")
expect(hookFile!.content).toContain("// Agent hook for Write|Edit: security-sentinel")
})
test("converts MCP servers", async () => {
const plugin = await loadClaudePlugin(fixtureRoot)
const bundle = convertClaudeToOpenCode(plugin, {
agentMode: "subagent",
inferTemperature: false,
permissions: "none",
})
const mcp = bundle.config.mcp ?? {}
expect(mcp["local-tooling"]).toEqual({
type: "local",
command: ["echo", "fixture"],
environment: undefined,
enabled: true,
})
expect(mcp.context7).toEqual({
type: "remote",
url: "https://mcp.context7.com/mcp",
headers: undefined,
enabled: true,
})
})
test("permission modes set expected keys", async () => {
const plugin = await loadClaudePlugin(fixtureRoot)
const noneBundle = convertClaudeToOpenCode(plugin, {
agentMode: "subagent",
inferTemperature: false,
permissions: "none",
})
expect(noneBundle.config.permission).toBeUndefined()
const broadBundle = convertClaudeToOpenCode(plugin, {
agentMode: "subagent",
inferTemperature: false,
permissions: "broad",
})
expect(broadBundle.config.permission).toEqual({
read: "allow",
write: "allow",
edit: "allow",
bash: "allow",
grep: "allow",
glob: "allow",
list: "allow",
webfetch: "allow",
skill: "allow",
patch: "allow",
task: "allow",
question: "allow",
todowrite: "allow",
todoread: "allow",
})
})
test("supports primary agent mode", async () => {
const plugin = await loadClaudePlugin(fixtureRoot)
const bundle = convertClaudeToOpenCode(plugin, {
agentMode: "primary",
inferTemperature: false,
permissions: "none",
})
const agentFile = bundle.agents.find((agent) => agent.name === "repo-research-analyst")
const parsed = parseFrontmatter(agentFile!.content)
expect(parsed.data.mode).toBe("primary")
})
test("excludes commands with disable-model-invocation from command map", async () => {
const plugin = await loadClaudePlugin(fixtureRoot)
const bundle = convertClaudeToOpenCode(plugin, {
agentMode: "subagent",
inferTemperature: false,
permissions: "none",
})
// deploy-docs has disable-model-invocation: true, should be excluded
expect(bundle.config.command?.["deploy-docs"]).toBeUndefined()
// Normal commands should still be present
expect(bundle.config.command?.["workflows:review"]).toBeDefined()
})
})