Skip to content

fix(opencode): ship @opencode-ai/plugin as a runtime dependency - #3561

Closed
gaurav0107 wants to merge 2 commits into
affaan-m:mainfrom
gaurav0107:fix/3543-opencode-plugin-runtime-dependency
Closed

gaurav0107 wants to merge 2 commits into
affaan-m:mainfrom
gaurav0107:fix/3543-opencode-plugin-runtime-dependency

Conversation

@gaurav0107

Copy link
Copy Markdown
Contributor

What Changed

  • Moved @opencode-ai/plugin (1.18.34, same exact pin) from devDependencies to dependencies in the root package.json, which is the manifest published as ecc-universal.
  • package-lock.json: the root entry moves, and "dev": true is dropped from @opencode-ai/plugin and its transitive deps. Nothing else changes. yarn.lock needs no change because the workspace entry already lists dev and runtime deps together (yarn install --mode=update-lockfile leaves it untouched).
  • New case in tests/scripts/build-opencode.test.js: walks the built .opencode/dist/**/*.js, collects every bare (non-builtin, non-relative) import, and asserts each package is declared in dependencies or peerDependencies.

Why This Change

Fixes #3543 (the bug report is in the issue's attached markdown file).

.opencode/dist/tools/*.js import tool from @opencode-ai/plugin/tool at module top level, and .opencode/dist/plugins/ecc-hooks.js imports those tools statically. OpenCode installs npm plugins without dev dependencies. So on any production install the first import throws and the whole plugin fails to load:

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@opencode-ai/plugin' imported from .../node_modules/ecc-universal/.opencode/dist/tools/changed-files.js

The existing tests didn't catch this because they symlink the repo's node_modules (which includes dev deps) into their fixtures.

Trade-off to weigh: @opencode-ai/plugin pulls in @opencode-ai/sdk, zod and effect. In my measurement, a production install of the packed tarball grew from about 54 MB to about 115 MB of node_modules. If that is too heavy for users who don't run OpenCode, two alternatives:

  • Declare it as a non-optional peerDependency. npm 7+ and Bun still install those by default, but the dependency weight is the same.
  • Stop importing the tool() helper at runtime and depend only on zod.

I kept the change to the fix the issue suggests, but I'm happy to switch to either.

Testing Done

  • Manual testing completed: ran npm pack, then in an empty host project npm install --omit=dev <tarball> and await import("ecc-universal").
    • On main: ERR_MODULE_NOT_FOUND: Cannot find package '@opencode-ai/plugin' (same error as the issue).
    • With this change: the plugin loads (typeof default === "function").
  • Automated tests pass locally (node tests/run-all.js). The new build-opencode case fails on main with undeclared runtime imports: @opencode-ai/plugin and passes with this change. All 10 cases in tests/scripts/build-opencode.test.js pass.
  • Edge cases considered and tested: type-only imports (import type { PluginInput }) are erased at compile time, so the check scans compiled output, not TS sources. Node builtins and node: specifiers are excluded, and scoped packages are reduced to @scope/name.

Also ran: validate-agents, validate-hooks, validate-commands, validate-skills, validate-install-manifests, validate-rules, catalog.js --text, command-registry:check, check-unicode-safety, validate-no-personal-paths, npm run lint, and scan-supply-chain-iocs. All pass.

Type of Change

  • fix: Bug fix
  • feat: New feature
  • refactor: Code refactoring
  • docs: Documentation
  • test: Tests
  • chore: Maintenance/tooling
  • ci: CI/CD changes

Security & Quality Checklist

  • No secrets or API keys committed (ghp_, sk-, AKIA, xoxb, xoxp patterns checked)
  • JSON files validate cleanly
  • Shell scripts pass shellcheck (if applicable): N/A
  • Pre-commit hooks pass locally (if configured): N/A
  • No sensitive data exposed in logs or output
  • Follows conventional commits format

If you changed dependencies or package.json (bin / files / deps)

  • Ran yarn install --mode=update-lockfile. yarn.lock is unchanged, because the workspace entry lists runtime and dev deps together.

Documentation

  • Updated relevant documentation: N/A (packaging fix)
  • Added comments for complex logic
  • README updated (if needed): N/A

🤖 Opened with Superhuman, an open-source contribution agent.

The compiled OpenCode tools import `tool` from `@opencode-ai/plugin/tool`
at module top level, and the hooks plugin imports those tools statically.
The package was only a devDependency, so production installs (OpenCode's
npm plugin cache, `npm install --omit=dev`) could not resolve it and the
whole plugin failed to load.

Move it to `dependencies` and add a build-opencode regression test that
fails when the built bundle imports a package not declared as a runtime
dependency.

Fixes affaan-m#3543
@ecc-tools

ecc-tools Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

ECC Tools / Security Evidence

Commit: 106024070efdc3fc1091c10b735cc24dac4a79a6

Security evidence gate passed (success)

No security-sensitive scanner-evidence gap detected.

Mode: enforce

Scanned 3 changed file(s). No missing scanner-evidence signal was detected.

Check publication was denied or unavailable. An app owner must enable Checks: read and write, and the installation owner must approve the updated permission.

@ecc-tools

ecc-tools Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

ECC Tools / PR Risk Taxonomy

Commit: 106024070efdc3fc1091c10b735cc24dac4a79a6

PR taxonomy review recommended (neutral)

Detected 2 PR taxonomy bucket(s): Install Manifest Integrity, CI/CD Recommendation.

Scanned 3 changed file(s).

Roadmap taxonomy buckets:

Install Manifest Integrity

Install manifests, plugin metadata, and shipped skills should stay synchronized with user-facing setup guidance.

Signals:

  • 2 install or manifest path(s) changed

Paths:

  • package-lock.json
  • package.json

CI/CD Recommendation

CI, dependency, coverage, and contract signals should be routed into follow-up checks or verification work.

Signals:

  • 3 CI or workflow path(s) changed

Paths:

  • package-lock.json
  • package.json
  • tests/scripts/build-opencode.test.js

Check publication was denied or unavailable. An app owner must enable Checks: read and write, and the installation owner must approve the updated permission.

@ecc-tools

ecc-tools Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

ECC Tools / Reference Set Readiness

Commit: 106024070efdc3fc1091c10b735cc24dac4a79a6

Reference set readiness gaps detected (neutral)

Reference evidence present for 0/7 areas (0%) across 3 changed file(s).

This check is based on files changed in this PR. Repository-level readiness is still reported by /ecc-tools analyze comments and generated manifests.

Area Status Evidence / Next Step
Deep analyzer corpus Missing Add analyzer fixture, golden, benchmark, or reference-set files that can catch analyzer regressions.
RAG/evaluator comparison Missing Add retrieval or evaluator reference-set comparison fixtures with expected ranking behavior.
PR salvage/review corpus Missing Add stale-PR, review-thread, reopen-flow, or salvage reference cases for queue cleanup automation.
Discussion triage corpus Missing Add public discussion triage fixtures, golden cases, or reference sets for informational, answered, and no-response classifications.
Harness compatibility Missing Add cross-harness, adapter-compliance, or harness-audit evidence for Claude, Codex, OpenCode, Zed, dmux, and agent surfaces.
Security evidence Missing Attach security evidence such as SBOMs, SARIF, audit reports, or AgentShield evidence packs.
CI failure-mode evidence Missing Add captured CI failure logs, dry-run fixtures, or troubleshooting docs for common workflow failure modes.

Check publication was denied or unavailable. An app owner must enable Checks: read and write, and the installation owner must approve the updated permission.

@ecc-tools

ecc-tools Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

ECC Tools / Hosted Promotion Readiness

Commit: 106024070efdc3fc1091c10b735cc24dac4a79a6

Hosted promotion readiness passed (success)

No hosted promotion evidence gaps detected across 3 changed file(s); 0 corpus scenarios had matching evidence.

This check compares PR file changes against the evaluator/RAG promotion corpus in src/analyzers/fixtures/evaluator-rag-corpus.ts.
Hosted output scoring inspected 0 completed cached hosted job results.

No evaluator corpus scenarios matched this PR.

Check publication was denied or unavailable. An app owner must enable Checks: read and write, and the installation owner must approve the updated permission.

@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⛔ Files ignored due to path filters: 1
  • package-lock.json is excluded by !**/package-lock.json
⚙️ Run configuration
  • Configuration used: Repository: affaan-m/ECC/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 8d7422e6-59c7-434a-84a7-74c6780c2279
📥 Commits

Reviewing files that changed from the base of the PR and between 1060240 and 6307519.

⛔ Files ignored due to path filters: 1
  • package-lock.json is excluded by !**/package-lock.json

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: affaan-m/ECC/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 736ebb15-f2bb-4a79-abd8-e181e24fd9cc
📥 Commits

Reviewing files that changed from the base of the PR and between b92f181 and 1060240.

⛔ Files ignored due to path filters: 1
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing: 2
  • package.json
  • tests/scripts/build-opencode.test.js

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📜 Recent review details
⏰ Context from checks skipped due to timeout: 1
  • GitHub Check: Greptile Review
🧰 Additional context used
📚 Code guidelines: 4
.cursor/rules/typescript-security.md — auto-discovered
.cursor/rules/common-hooks.md — auto-discovered
.cursor/rules/typescript-coding-style.md — auto-discovered
.cursor/rules/typescript-hooks.md — auto-discovered
📓 Path-based instructions: 4
Source excerpt: Source excerpt: Use **security-reviewer** skill for comprehensive security audits

📄 CodeRabbit inference engine (.cursor/rules/typescript-security.md)

Files:

  • tests/scripts/build-opencode.test.js
Source excerpt: Use with caution: Source excerpt: Use with caution: Enable for trusted, well-defined plans Source excerpt: Use with caution: Disable for exploratory work Source excerpt: Use with caution: Never use dangerously-skip-permissio...

📄 CodeRabbit inference engine (.cursor/rules/common-hooks.md)

Files:

  • tests/scripts/build-opencode.test.js
  • package.json
Source excerpt: Use spread operator for immutable updates: Source excerpt: Use async/await with try-catch: Source excerpt: Use Zod for schema-based validation: Source excerpt: Use proper logging libraries instead

📄 CodeRabbit inference engine (.cursor/rules/typescript-coding-style.md)

Files:

  • tests/scripts/build-opencode.test.js
Source excerpt: **console.log audit**: Check all modified files for `console.log` before session ends

📄 CodeRabbit inference engine (.cursor/rules/typescript-hooks.md)

Files:

  • tests/scripts/build-opencode.test.js
  • package.json
🪛 ast-grep (0.45.3)
tests/scripts/build-opencode.test.js

[error] 131-131: An archive entry path (e.g. entry.path / entry.fileName / header.name) is joined to an output directory without validating that the resolved path stays inside that directory. A malicious archive can use "../" sequences to escape the extraction directory and overwrite arbitrary files (Zip Slip). Resolve the path and verify it starts with the normalized output directory, or strip traversal with path.basename, before writing the entry.
Context: path.join(dir, entry.name)
Note: [CWE-22] Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').

(zip-slip-archive-extraction-javascript)

[warning] 135-135: Filesystem path is not a string literal; a request-/variable-derived path can enable path traversal. Validate and normalize the path before use.
Context: fs.readFileSync(entryPath, "utf8")
Note: [CWE-22] Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').

(detect-non-literal-fs-filename)

🔇 Additional comments: 1
package.json: 1

546-546: 🗄️ Data Integrity & Integration

The root package-lock.json already classifies @opencode-ai/plugin under packages[""].dependencies and not under devDependencies. The package entry is also present, so the proposed lockfile update is not needed.

📝 Summary

Summary by CodeRabbit

  • Improvements
    • The OpenCode plugin is now included in production installations.

The package manifest moves @opencode-ai/plugin into runtime dependencies. A test checks that package imports in the built OpenCode JavaScript bundle are declared in runtime or peer dependencies.

Changes: Runtime dependency validation

Layer / File(s) Summary
Declare and validate bundle dependencies
package.json, tests/scripts/build-opencode.test.js
@opencode-ai/plugin moves from devDependencies to dependencies. The test scans bundled JavaScript imports, excludes Node built-ins, and checks that imported packages are declared in dependencies or peerDependencies.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 10602

The dependency declaration addresses the reported production-install failure. No actionable merge-blocking risk remains after normal checks.

Security architecture risk: 🟡 Moderate · up to 10602

The dependency change correctly supplies an existing runtime import without changing its version. However, successful production loading also activates existing permission and lifecycle behavior. A permissive command-prefix approval callback presents a conditional security concern; its effect on actual command authorization remains unverified.

Retained concerns

  • Medium · security · inferred: Successful production-only loading exposes an existing permission callback that approves Bash commands by prefix. For example, a command beginning with npm test followed by a semicolon and another command still satisfies the approval expression. If OpenCode honors this returned approval, agent-influenced command arguments could cross the user-approval boundary and execute additional commands with the host account's authority. The callback predates this PR and was already available where dependencies were installed; the changed exposure is activation for previously failing production-only installs. Actual host dispatch and enforcement of the returned decision are not established by the available evidence.
Security review details

Security Blast Radius

  • inferred — Installation-time exposure extends to root-package consumers when optional dependencies and lifecycle scripts are enabled. Conditional permission-control exposure is narrower: configured OpenCode consumers whose host invokes and honors the callback. Potential command execution would inherit that host account's available filesystem and credentials; cross-tenant or cloud-wide authority is not established.

Security Findings and Attack Paths

  • inferred — The conditional attack path is an agent-influenced Bash command, a permitted formatter or test prefix, callback approval, and host execution of the complete command. The prefix expressions do not constrain shell composition. Available tests demonstrate callback approval for ordinary commands, not an end-to-end host authorization bypass.

Trust Boundaries and Controls

  • observed — The permission callback defers unrecognized operations and returns denial on errors within its permission-handling try block. Those controls do not apply to commands accepted by the earlier prefix checks. Tests call the callback directly, leaving the host's authorization contract unresolved.

Resilience and Maintainability Implications

  • observed — Existing initialization catches failures loading secondary tracking modules, preserving remaining hooks. Shared changed-file state has no session ownership key, and cleanup depends on an enabled session-deletion callback. This predates the PR; host instance isolation and interrupted-session recovery are not established, so cross-session leakage is not reported as verified.

Hardening Proposals

  • proposed — Validate the real host permission contract before relying on automatic approval. Where approval is effective, defer composite shell commands to host policy rather than treating an executable-name prefix as approval of the complete command.
  • proposed — Complement declaration validation with isolated production-package loading and lifecycle checks, including disabled or failing optional native installation and overlapping or interrupted sessions. Keep installation credentials limited to what package installation requires.
Pre-merge checks: Passed 3 · Failed 1 · Inconclusive 1

Failed Failed checks: 1 warning · 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
Linked Issues check Inconclusive Issue #3543 is directly linked and remains open, but its acceptance criteria are only in an unavailable attached file. The supplied PR evidence shows a focused fix: @opencode-ai/plugin moves to runt… Provide the contents of the #3543 attachment or its acceptance criteria so the full coding requirements can be checked.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely identifies the main change: shipping @opencode-ai/plugin as a runtime dependency. It matches the package manifest update and the production-install fix.
Description check Passed The description directly explains the dependency change, the production-install failure, the regression test, testing performed, and the known package-size trade-off. It is clearly related to the chan…
Out of Scope Changes check Passed The reviewed changes are limited to the dependency declaration and a regression test for the reported OpenCode production-install failure in #3543. The test directly verifies the required runtime-impo…
Full details: Linked Issues check

Explanation

Issue #3543 is directly linked and remains open, but its acceptance criteria are only in an unavailable attached file. The supplied PR evidence shows a focused fix: @opencode-ai/plugin moves to runtime dependencies, and a compiled-bundle import test checks declared runtime imports. This evidence supports the reported production-install bug, but it cannot establish compliance with all requirements in #3543.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gaurav0107
gaurav0107 marked this pull request as ready for review October 13, 2026 20:50
@gaurav0107
gaurav0107 requested a review from affaan-m as a code owner October 13, 2026 20:50
@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] Safe to merge based on the reviewed changes. No blocking findings remain.

Summary

Moves @opencode-ai/plugin into runtime dependencies so OpenCode can load the published package without development dependencies.

  • OpenCode installs now include the package its compiled plugin needs.

No actionable issues found. Tests were not run during this review.

Reviews (2) · Last reviewed commit: "Merge branch 'main' into fix/3543-openco..." · Reviewed by Greptile

@ecc-tools

ecc-tools Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

ECC Tools / Security Evidence

Commit: 63075198851d4253268b6aef09d635f48ccff981

Security evidence gate passed (success)

No security-sensitive scanner-evidence gap detected.

Mode: enforce

Scanned 3 changed file(s). No missing scanner-evidence signal was detected.

Check publication was denied or unavailable. An app owner must enable Checks: read and write, and the installation owner must approve the updated permission.

@ecc-tools

ecc-tools Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

ECC Tools / PR Risk Taxonomy

Commit: 63075198851d4253268b6aef09d635f48ccff981

PR taxonomy review recommended (neutral)

Detected 2 PR taxonomy bucket(s): Install Manifest Integrity, CI/CD Recommendation.

Scanned 3 changed file(s).

Roadmap taxonomy buckets:

Install Manifest Integrity

Install manifests, plugin metadata, and shipped skills should stay synchronized with user-facing setup guidance.

Signals:

  • 2 install or manifest path(s) changed

Paths:

  • package-lock.json
  • package.json

CI/CD Recommendation

CI, dependency, coverage, and contract signals should be routed into follow-up checks or verification work.

Signals:

  • 3 CI or workflow path(s) changed

Paths:

  • package-lock.json
  • package.json
  • tests/scripts/build-opencode.test.js

Check publication was denied or unavailable. An app owner must enable Checks: read and write, and the installation owner must approve the updated permission.

@ecc-tools

ecc-tools Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

ECC Tools / Reference Set Readiness

Commit: 63075198851d4253268b6aef09d635f48ccff981

Reference set readiness gaps detected (neutral)

Reference evidence present for 0/7 areas (0%) across 3 changed file(s).

This check is based on files changed in this PR. Repository-level readiness is still reported by /ecc-tools analyze comments and generated manifests.

Area Status Evidence / Next Step
Deep analyzer corpus Missing Add analyzer fixture, golden, benchmark, or reference-set files that can catch analyzer regressions.
RAG/evaluator comparison Missing Add retrieval or evaluator reference-set comparison fixtures with expected ranking behavior.
PR salvage/review corpus Missing Add stale-PR, review-thread, reopen-flow, or salvage reference cases for queue cleanup automation.
Discussion triage corpus Missing Add public discussion triage fixtures, golden cases, or reference sets for informational, answered, and no-response classifications.
Harness compatibility Missing Add cross-harness, adapter-compliance, or harness-audit evidence for Claude, Codex, OpenCode, Zed, dmux, and agent surfaces.
Security evidence Missing Attach security evidence such as SBOMs, SARIF, audit reports, or AgentShield evidence packs.
CI failure-mode evidence Missing Add captured CI failure logs, dry-run fixtures, or troubleshooting docs for common workflow failure modes.

Check publication was denied or unavailable. An app owner must enable Checks: read and write, and the installation owner must approve the updated permission.

@ecc-tools

ecc-tools Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

ECC Tools / Hosted Promotion Readiness

Commit: 63075198851d4253268b6aef09d635f48ccff981

Hosted promotion readiness passed (success)

No hosted promotion evidence gaps detected across 3 changed file(s); 0 corpus scenarios had matching evidence.

This check compares PR file changes against the evaluator/RAG promotion corpus in src/analyzers/fixtures/evaluator-rag-corpus.ts.
Hosted output scoring inspected 0 completed cached hosted job results.

No evaluator corpus scenarios matched this PR.

Check publication was denied or unavailable. An app owner must enable Checks: read and write, and the installation owner must approve the updated permission.

@haelyra

haelyra commented Oct 25, 2026

Copy link
Copy Markdown
Collaborator

Thank you for catching the OpenCode runtime import failure and proposing the direct-Zod alternative we used. We carried your contribution into #3654 with attribution and the related follow-up fixes. That integration merged as e494799, and the resulting main passed CI, CodeQL, and Supply-Chain Watch. I’m closing this source PR as delivered. We appreciate your work and hope you’ll keep contributing.

@haelyra haelyra closed this Oct 25, 2026
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.

ecc-bug

2 participants