Skip to content

Feature: per-target agent frontmatter transformation during deployment #581

@Mathf18

Description

@Mathf18

Problem

When APM deploys agent .md files from a marketplace plugin to multiple targets (Claude Code, OpenCode, Codex, etc.), it copies the same file verbatim to each target directory (.claude/agents/, .opencode/agents/, .codex/agents/).

This causes hard crashes on platforms with different frontmatter schemas.

tools field

  • Claude Code expects: comma-separated string or array → tools: Read, Grep, Glob or tools: ["Read", "Grep"]
  • OpenCode expects: record/object → tools: {Read: true, Grep: true} (Zod schema: z.record(z.string(), z.boolean()))
  • Result: OpenCode throws InvalidError ("expected record, received array") — hard crash, unrecoverable

color field

  • Claude Code expects: named colors → color: cyan, color: yellow
  • OpenCode expects: hex #RRGGBB or theme names (primary, secondary, accent, success, warning, error, info)
  • Result: OpenCode throws InvalidError ("Invalid hex color format")

Impact on OpenCode

OpenCode's loadAgent() function calls Agent.safeParse() on the parsed frontmatter. On validation failure, it throws an InvalidError with no catch — a single bad agent file kills the entire application startup. There is no graceful degradation or per-file skip on validation failure.

APM already detects the problem but only during compile

apm compile warns about these files with "Failed to parse primitive ... mapping values are not allowed in this context" — but apm install (which deploys the files) does not validate or warn. The broken files are deployed silently.

Proposed solutions

Option A: Transform frontmatter per target during apm install

During apm install --target <platform>, APM transforms agent frontmatter fields to the target platform's expected format:

  1. tools: Convert between array/string (Claude) ↔ record (OpenCode) formats
  2. color: Convert between named colors (Claude) ↔ hex/theme names (OpenCode)
  3. Unknown fields: Strip fields not supported by the target platform

This would allow plugin authors to write agent files once in any supported format, and APM would handle the translation during deployment.

Option B: Validate and warn during install (not just compile)

apm install should validate agent frontmatter against the target platform's schema and warn about incompatible fields before deploying, rather than silently deploying broken files that crash the target tool. The validation logic already exists in apm compile — it should also run during apm install.

Related

Environment

  • APM version: 0.8.10
  • Plugin: data-goblin/power-bi-agentic-development v0.17.2
  • Targets affected: OpenCode (confirmed hard crash), potentially Codex and Cursor

Metadata

Metadata

Assignees

Labels

area/content-securityUnicode scanning, Glassworm, apm audit content checks, SARIF output.area/multi-targetMulti-target deploy spec, target directory creation, agent surface routing.enhancementDeprecated: use type/feature. Kept for issue history; will be removed in milestone 0.10.0.needs-designDeprecated: use status/needs-design. Kept for issue history; will be removed in milestone 0.10.0.status/needs-designDirection approved, design discussion required before code.status/triagedInitial agentic triage complete; pending maintainer ratification (silence = approval).theme/portabilityOne manifest, every target. Multi-target deploy, marketplace, packaging, install.type/bugSomething does not work as documented.

Type

No type
No fields configured for issues without a type.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions