Skip to content

fix(plugin): preserve cross-zod tool arg metadata#2372

Open
code-yeongyu wants to merge 1 commit intodevfrom
fix/issue-2314
Open

fix(plugin): preserve cross-zod tool arg metadata#2372
code-yeongyu wants to merge 1 commit intodevfrom
fix/issue-2314

Conversation

@code-yeongyu
Copy link
Owner

@code-yeongyu code-yeongyu commented Mar 7, 2026

Summary

  • add a plugin-side schema normalization hook so tool arg schemas can self-serialize with the plugin's Zod instance before OpenCode converts them
  • wire the normalization into tool registration so nested descriptions and metadata survive cross-Zod-instance registration
  • add a regression test covering the metadata loss case with a separate host Zod instance

Verification

  • bun test
  • bun test src/plugin/normalize-tool-arg-schemas.test.ts
  • bun run typecheck
  • bun run build

Summary by cubic

Preserves tool arg descriptions and metadata across different Zod instances by normalizing schemas during tool registration. Fixes metadata loss reported in issue 2314.

  • Bug Fixes
    • Added normalizeToolArgSchemas to patch arg schemas to self-serialize via the plugin’s Zod (strips $schema).
    • Wired normalization into tool registration so nested titles/descriptions/examples survive.
    • Added a regression test using a separate host Zod to verify preservation.

Written for commit d84c28d. Summary will update on new commits.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 3 files

Confidence score: 4/5

  • This PR is likely safe to merge, with a small but real risk coming from a medium-severity, high-confidence test fragility in src/plugin/normalize-tool-arg-schemas.test.ts.
  • Hardcoding node_modules in the test can fail in hoisted or nonstandard package layouts, which may cause avoidable CI/test regressions even if runtime behavior is unchanged.
  • Pay close attention to src/plugin/normalize-tool-arg-schemas.test.ts - replace hardcoded node_modules resolution with dynamic zod package path discovery to keep tests environment-agnostic.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/plugin/normalize-tool-arg-schemas.test.ts">

<violation number="1" location="src/plugin/normalize-tool-arg-schemas.test.ts:24">
P2: Do not hardcode `node_modules` paths, as dependency hoisting can cause this directory to not exist. Resolve the `zod` package location dynamically instead.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.


async function loadSeparateHostZodModule(): Promise<typeof import("zod")> {
const pluginPackageDirectory = dirname(Bun.resolveSync("@opencode-ai/plugin/package.json", import.meta.dir))
const sourceZodDirectory = join(pluginPackageDirectory, "node_modules", "zod")
Copy link

@cubic-dev-ai cubic-dev-ai bot Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Do not hardcode node_modules paths, as dependency hoisting can cause this directory to not exist. Resolve the zod package location dynamically instead.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/plugin/normalize-tool-arg-schemas.test.ts, line 24:

<comment>Do not hardcode `node_modules` paths, as dependency hoisting can cause this directory to not exist. Resolve the `zod` package location dynamically instead.</comment>

<file context>
@@ -0,0 +1,97 @@
+
+async function loadSeparateHostZodModule(): Promise<typeof import("zod")> {
+  const pluginPackageDirectory = dirname(Bun.resolveSync("@opencode-ai/plugin/package.json", import.meta.dir))
+  const sourceZodDirectory = join(pluginPackageDirectory, "node_modules", "zod")
+  const tempDirectory = mkdtempSync(join(tmpdir(), "omo-host-zod-"))
+  const copiedZodDirectory = join(tempDirectory, "zod")
</file context>
Fix with Cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant