Skip to content

fix(opencode): avoid duplicate home plugin initialization - #3441

Merged
haelyra merged 1 commit into
affaan-m:mainfrom
xiehuanyi:fix/opencode-single-plugin-round2
Oct 11, 2026
Merged

haelyra merged 1 commit into
affaan-m:mainfrom
xiehuanyi:fix/opencode-single-plugin-round2

Conversation

@xiehuanyi

Copy link
Copy Markdown
Contributor

Home-target OpenCode installs now keep the redundant plugins/index.ts barrel inert, including when hooks are explicitly enabled. OpenCode discovers ecc-hooks.ts itself; loading its re-export again initialized each ECC hook twice. The source/package barrel and published module imports remain intact, and install-state records the inert transform for repair/reinstall.

Fixes #3427.

Validation: installed-barrel assertion fails before the change; install executor 24 checks, consent 12 checks, and lifecycle 73 checks pass. ESLint passes. Full npm test using native Git: 6,193 checks pass; one unchanged upstream Codex folded-case hook assertion fails. Its code is outside this diff.

Implemented with OpenAI Codex.

Copilot AI balanced review requested due to automatic review settings October 6, 2026 16:43
@xiehuanyi
xiehuanyi requested a review from affaan-m as a code owner October 6, 2026 16:43
@ecc-tools

ecc-tools Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

ECC Tools / Security Evidence

Commit: 990e45e177ef24c8f257398b50305ddc10109c66

Security evidence gate passed (success)

No security-sensitive scanner-evidence gap detected.

Mode: enforce

Scanned 4 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@ecc-tools

ecc-tools Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

ECC Tools / PR Risk Taxonomy

Commit: 990e45e177ef24c8f257398b50305ddc10109c66

PR taxonomy review recommended (neutral)

Detected 5 PR taxonomy bucket(s): Harness Drift, Install Manifest Integrity, CI/CD Recommendation, Reference Set Validation, Agent Config Review.

Scanned 4 changed file(s).

Roadmap taxonomy buckets:

Harness Drift

Harness-facing changes can drift across Claude Code, Codex, OpenCode, and shared adapter surfaces.

Signals:

  • Harness config changes may ship without compatibility evidence
  • 1 harness-facing path(s) changed

Paths:

  • .opencode/README.md

Install Manifest Integrity

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

Signals:

  • 1 install or manifest path(s) changed

Paths:

  • .opencode/README.md

CI/CD Recommendation

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

Signals:

  • 2 CI or workflow path(s) changed

Paths:

  • tests/lib/hook-consent.test.js
  • tests/lib/install-executor.test.js

Reference Set Validation

AI, analyzer, skill, agent, command, and harness guidance changes should be compared against a maintained eval, golden trace, benchmark, or reference set.

Signals:

  • AI or harness analysis changes may ship without reference-set validation
  • 1 reference-sensitive path(s) changed

Paths:

  • .opencode/README.md

Agent Config Review

Agent, command, skill, MCP, and local instruction changes should be reviewed as executable agent configuration.

Signals:

  • 1 agent-config path(s) changed

Paths:

  • .opencode/README.md

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 6, 2026

Copy link
Copy Markdown
Contributor

ECC Tools / Reference Set Readiness

Commit: 990e45e177ef24c8f257398b50305ddc10109c66

Reference set readiness gaps detected (neutral)

Reference evidence present for 1/7 areas (14%) across 4 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 Present .opencode/README.md
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 6, 2026

Copy link
Copy Markdown
Contributor

ECC Tools / Hosted Promotion Readiness

Commit: 990e45e177ef24c8f257398b50305ddc10109c66

Hosted promotion readiness passed (success)

No hosted promotion evidence gaps detected across 4 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 6, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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: a956b982-3e2d-400b-8929-7a39e64e3aae
📥 Commits

Reviewing files that changed from the base of the PR and between ef648e0 and 990e45e.

📒 Files selected for processing (4)
  • .opencode/README.md
  • scripts/lib/install/hook-consent.js
  • tests/lib/hook-consent.test.js
  • tests/lib/install-executor.test.js

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

📜 Recent review details
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: Greptile Review
🧰 Additional context used
📚 Code guidelines (3)
.cursor/rules/typescript-security.md — auto-discovered
.cursor/rules/typescript-coding-style.md — auto-discovered
.cursor/rules/typescript-hooks.md — auto-discovered
📓 Path-based instructions (4)
Focus on command injection, unsafe subprocess usage, path traversal, SSRF, secret exposure, and missing tests for new CLI behavior.

⚙️ CodeRabbit configuration file

Files:

  • scripts/lib/install/hook-consent.js
Source excerpt: Source excerpt: Use **security-reviewer** skill for comprehensive security audits

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

Files:

  • tests/lib/hook-consent.test.js
  • tests/lib/install-executor.test.js
  • scripts/lib/install/hook-consent.js
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/lib/hook-consent.test.js
  • tests/lib/install-executor.test.js
  • scripts/lib/install/hook-consent.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/lib/hook-consent.test.js
  • tests/lib/install-executor.test.js
  • scripts/lib/install/hook-consent.js
🪛 ast-grep (0.45.3)
tests/lib/install-executor.test.js

[warning] 993-993: 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(path.join(REPO_ROOT, '.opencode', 'plugins', name), 'utf8')
Note: [CWE-22] Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').

(detect-non-literal-fs-filename)

🔇 Additional comments (1)
scripts/lib/install/hook-consent.js (1)

195-196: 🎯 Functional Correctness

The supported compiled barrel can remain an install operation, but the repository does not configure it as a second OpenCode plugin. .opencode/opencode.json loads ./plugins; .opencode/dist/plugins/index.js is a package export. Deactivating that export would risk breaking the published package entrypoint, so the proposed matching change is not supported.


📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • OpenCode installations with hooks enabled now keep the plugin barrel inactive, preventing hooks from being initialized twice while preserving other plugin entrypoints.
  • Documentation
    • Clarified how OpenCode loads hooks and why the plugin barrel remains inactive in home-target installations.

Walkthrough

OpenCode install plans now keep plugins/index.ts inert when hooks are enabled. The plan and state preview apply the entrypoint transform, and tests verify the resulting plan and installed content.

Changes

OpenCode plugin entrypoint handling

Layer / File(s) Summary
Transform OpenCode entrypoint operations
scripts/lib/install/hook-consent.js, tests/lib/hook-consent.test.js, tests/lib/install-executor.test.js, .opencode/README.md
Enabled plans preserve activation for .opencode/plugins/index.ts while disabling other OpenCode hook entrypoints. The same transformation applies to state-preview operations. Tests check the transforms and installed content. The README documents why the barrel remains inert.

Priority: ➖ Normal

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

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 990e4

The supplied checks cover the inert-barrel behavior in the plan and installed content, with no established merge-blocking risk.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 990e4

The change disables duplicate hook loading without weakening the existing opt-in requirement. No expanded execution authority was identified. Risk remains low because interrupted upgrades and actual plugin discovery were not fully validated.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed execution surface is duplicate plugin initialization in the user's OpenCode installation. Because the selected ecc-hooks.ts runtime remains active as before and the barrel loses its import, the inspected delta reduces an activation path rather than adding an attacker-controlled input or execution privilege. This conclusion does not assess every existing hook capability.

Trust Boundaries and Controls

  • observed — The existing consent check runs before installation, and OpenCode installation acquires its installation locks. Repair's copy-file handling treats install state as attacker-controllable and confines writes to an adapter-derived trusted root. The new transform does not alter these control implementations.

Resilience and Maintainability Implications

  • inferred — Ordinary installation writes remain sequential, with final state persisted afterward. An interrupted upgrade can therefore leave the prior active barrel or transformed bytes under stale state. This non-transactional behavior predates the PR; the inspected change does not establish greater exposure than the prior active configuration. Recovery without a valid state record and crash timing between plugin writes remain incompletely validated.

Hardening Proposals

  • proposed — Add focused interruption coverage around the two plugin writes and final state persistence, including recovery with stale and absent state. This would validate recovery guarantees; it is not evidence of an introduced vulnerability.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

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 5 functions across 3 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: preventing duplicate OpenCode plugin initialization in home-target installs.
Description check ✅ Passed The description explains the inert plugin barrel change, its reason, and the reported validation results.
Linked Issues check ✅ Passed [3427] requires one OpenCode hook initialization per session. For home-target OpenCode plans, disableUnselectedOpenCodeHooks now applies opencode-disable-plugin-entrypoint to `.opencode/plugins/in…
Out of Scope Changes check ✅ Passed All changed files support [3427]. The installer change prevents duplicate plugin loading. The tests verify the enabled-install output and recorded state. The README documents the behavior. The diff sh…
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 5 functions across 3 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · 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.

@greptile-apps

greptile-apps Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Changes how OpenCode plugin initialization is controlled during installation.

Safe to merge based on the verified installation and lifecycle behavior; no blocking issues were found.

What we checked:

  • Enabled hooks stay active: The change targets index.ts. The enabled-install test separately checks that ecc-hooks.ts retains its source bytes. T-Rex
  • Repair uses inactive bytes: Repair bypasses the saved digest for this transform and compares the file against the inactive bytes. Files that differ are selected for repair. T-Rex
  • Executed node trex-artifacts/run-opencode-consent-checks.cjs from the repository; the run completed with exit code 0 and the runner captured every subprocess command, its working directory, exit code, and observed output. T-Rex
  • Compared the pre-change and post-change sources to verify consent hooks behavior, noting that the pre-change hook-consent.js produced hooks while the post-change source installed index.ts returned {} and only ecc-hooks.ts produced hooks with a single permission-callback log. T-Rex
  • Enabled the installed ecc-hooks.ts and confirmed it matched the source byte-for-byte, while declined entrypoints returned {}; the source barrel and built plugin exports retained the original function identity and unchanged bytes. T-Rex
  • Reproduced the opencode lifecycle checks; the final build, before, after, and lifecycle-suite commands all exited 0, and earlier setup hiccups from a temporary-directory fixture and missing build output were resolved so the final captures passed. T-Rex
Summary

Home OpenCode installs now keep plugins/index.ts inactive even when hooks are enabled. ecc-hooks.ts stays active, and the inactive-barrel transform is recorded for repair and reinstall. The source and published package barrels remain available for module imports, and the README explains the installed-file difference.

Executed checks confirmed the installed entrypoint behavior, preserved package exports, and correct repair and reinstall behavior, including upgrades from installations with an active barrel. The consent, executor, and lifecycle suites passed all 12, 24, and 73 checks respectively.

No actionable issues were found. The verified installation and lifecycle behavior supports merging this change.

Reviews (1) · Last reviewed commit: "fix(opencode): avoid duplicate home plug..."

@haelyra

haelyra commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

Thank you for preventing duplicate OpenCode home hook initialization. The installed barrel stays inert while ecc-hooks.ts remains active, including with explicit hook consent. Installed-file, consent and repair/uninstall lifecycle checks passed.

This contribution is delivered on main through #3495, preserving the reviewed source commits and the maintainer fixes described above. The exact integration and resulting main passed the delivery checks. Thank you for helping improve ECC.

The discovery probe loads actual installed TypeScript modules and verifies one live entrypoint; it does not claim a native OpenCode startup run.

Verified main: 2d515e4f. CI CodeQL Supply-Chain Watch

@haelyra
haelyra merged commit 423edc1 into affaan-m:main Oct 11, 2026
3 checks passed
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.

OpenCode: plugins/index.ts re-export makes ECCHooksPlugin initialise twice

3 participants