Skip to content

fix(opencode): preserve v2 hook and plugin directory packages - #915

Merged
runkids merged 5 commits into
runkids:mainfrom
salmonumbrella:fix/opencode-v2-packages
Nov 15, 2026
Merged

runkids merged 5 commits into
runkids:mainfrom
salmonumbrella:fix/opencode-v2-packages

Conversation

@salmonumbrella

Copy link
Copy Markdown
Contributor

Type

  • Bug fix

Linked issue

Refs #913.

What changed

OpenCode v2 hook and plugin registration preserves package directories and manifests, instead of registering an entry file. OpenCode v1 retains its flat-file behavior; unknown versions are rejected. Imported local packages keep declared dependency metadata; Skillshare does not execute those packages or install their dependencies. Receipt handling preserves account ownership across sync and removal, and the dashboard surfaces localized validation messages.

This is a single compatibility proposal. It touches the CLI, dashboard, tests and translated docs; the linked issue does not currently have an approved label. AI-assisted implementation and review; no human-review attestation is made here.

Verification

  • Independent static review of the candidate and follow-up changes.
  • Diff whitespace, context-router, and changed JSON and locale checks passed.
  • Devcontainer make check, scoped Go unit/integration tests, dashboard tests/build and browser interaction checks were not run. The available VM has no devcontainer.
  • The fork-only exact-source test workflow did not start. This draft does not claim passing runtime tests or hosted CI.

Published head dfc490c5 has the exact reviewed source tree 45ebabfe2bc63afd3cf49cba1e9d16ea5a3b6721. No live OpenCode configuration or package execution was used.

Checklist

  • Linked issue and focused compatibility scope
  • Human author review
  • Runtime checks passing

Opened at the contributor’s direction as a draft for validation.

Stage the reviewed issue 913 source for isolated fork validation. Preserve
package directories and manifests without executing managed packages or
installing their dependencies, and include receipt and localized UI fixes.

Reviewed local source: 15ac88e2f266571b8a6dc8d777302db0f4dcae44
Exact source tree: 45ebabf

Static checks and independent inspection completed. Go, integration,
dashboard, rendering, and hosted runtime validation remain pending.
This fork staging commit is not an upstream publication or merge.
Check the version-aware binding schema and verify native unregister retains the unchanged managed snapshot.
@salmonumbrella
salmonumbrella marked this pull request as ready for review November 15, 2026 01:01
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T17:30:08.335164Z 65a8ffa Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 11ae3119ea

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/hooks/opencode.go Outdated
probe = func(bin string) (string, error) {
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
cmd := exec.CommandContext(ctx, bin, "--version")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Handle Windows npm shims in the OpenCode version probe

On Windows when OpenCode is installed through npm and opencode resolves to opencode.cmd, this attempts to launch a batch file directly. Go's os/exec documentation explicitly states that it “does not invoke the system shell,” so the probe fails to start instead of returning a version. Because renderScope and native importCode now require this probe, even OpenCode v1 users lose previously working hook synchronization and imports despite being able to run OpenCode from their terminal. Resolve the underlying executable or safely handle Windows batch launchers, and cover the default probe rather than only injected version callbacks.

Useful? React with 👍 / 👎.

Probe recognized native Opencode executables without invoking a batch shell; exercise the default version probe on hosted Windows.
Avoid doubling carriage returns when Git checks out the npm fixture with CRLF.
@runkids

runkids commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Thanks for working on this, and for the detailed write-up in #913. The overall approach (probe the installed API, keep v1 flat files, register v2 directory packages, never run plugin code or install dependencies) matches what the issue asks for. The earlier Windows npm shim finding is resolved by 6ea1997: it only matches the fixed cmd-shim template and never invokes cmd.exe.

I reviewed the PR head (d1524ce) by reading the code; I did not run tests locally (CI is green). Findings below, grouped by kind and ordered by severity within each group. Paths are at the PR head.

Correctness

  1. A failed opencode --version probe aborts the whole hooks plan for every agent. (internal/hooks/plan.go:233, internal/hooks/opencode.go:45)
    renderScope returns the probe error, so hooks sync, status, doctor and the dashboard preview all fail once any entry has an opencode binding and opencode is not on PATH, for example on a second machine that shares hooks.yaml, in CI, or in a devcontainer. Claude, Codex and the other agents stop syncing too. In 0.30.8 the v1 flat file needed no binary. The error suggests setting the account cli, but the built-in opencode target has no cli (opencode.go:21 reads it only for a scoped account). The probe is also not cached: it runs once per binding, up to 3s each. I think this is the one blocker: a probe failure should affect only OpenCode bindings, not the whole plan.

  2. One symlink inside any unowned directory under plugins/ fails the whole OpenCode import on v2. (internal/hooks/opencode.go:155-172)
    With plugins/mytool/bin -> ../x, safeRead rejects the symlink and the walk error is returned from importCode. Every OpenCode candidate disappears, including flat .ts files. Skipping (or flagging) that one package would keep the rest importable.

  3. Possible double management between hooks and plugins (not fully traced). (internal/plugin/package_config.go:255)
    Hooks now writes file:///…/plugins/skillshare-NAME into the plugins array. openCodeInventory has no hooks-ownership filter, and openCodeImportRoot now accepts directories. So a synced v2 hook may show up in plugin list and plugin import as an importable native plugin.

Repository rules

  1. The runbook's Expected blocks are not machine-checkable. (ai_docs/tests/opencode_packages_runbook.md:25,37,49)
    - Exit code: 0 and - Output contains: are not mdproof assertions, so those steps cannot fail. The other runbooks use - exit_code: 0 and - regex: ... (see wiki/e2e-runbooks.md, Runbook Quality Checklist).

Spec coverage (#913)

  1. Several lifecycle paths from the issue have no tests:

    • updating a hooks package binding;
    • hooks import in project scope and for accounts (only global is tested);
    • the "directory package requires OpenCode v2" error on a v1 host (plan.go:246);
    • probe failure through Preview and Import;
    • the blocked result for a v2 plugin source without package.json or exports.
  2. code is not checked for v2 shape. (judgement call)
    On v2, any code binding is wrapped into a package, so v1-style named exports still produce a clean v2 plan. The issue allows "preserve or generate", and the shape cannot be verified offline, so this may be acceptable. Please state it in the docs if so.

Consumers

  1. The v2 dependency warning makes doctor permanently yellow. (internal/hooks/opencode.go:130, plan.go:513, cmd/skillshare/doctor_resources.go:151)
    The warning is appended for every v2 binding on every preview, so doctor never reports hooks as in sync on v2. N hooks give N identical warnings.

  2. Directories are listed as unmanaged hooks on v1 too. (internal/hooks/inventory.go:164)
    The directory branch does not check the version, so a helper folder such as plugins/lib/ appears in hooks list and the dashboard on OpenCode 1.x.

  3. Package validation errors appear twice, and one copy stays in English. (internal/hooks/inventory.go:300)
    The second copy has a hook NAME: prefix, which does not match the regexes in hooksView.ts, so the dashboard shows it untranslated in every locale.

  4. The translated docs do not match the English pages. (website/i18n/{ja,ko,zh-Hans,zh-Hant}/…/reference/commands/hooks.md and plugin.md)

    • The OpenCode table cell is English and differs from the English text.
    • The prose is condensed and omits the project registration path, the OPENCODE_CONFIG / OPENCODE_CONFIG_CONTENT refusal, JSONC comment preservation and the external-edit conflict.
    • The translated plugin.md adds a hooks-specific ### OpenCode v2 section that the English page does not have.
  5. The YAML editor has no field help for package. (ui/src/lib/fieldDocs.ts:43)
    There is no hooks.entries.bindings.package entry, and the code description does not mention package.

  6. State dimensions with no test:

    • a missing opencode binary;
    • an account with cli set (the injected probe ignores bin);
    • a moved v2 account home;
    • project-mode v2 re-sync, removal and restore;
    • a v2 to v1 downgrade;
    • hooks and plugins sharing one opencode.json.

Cleanup (judgement calls)

  • The version probe is implemented twice. internal/hooks/opencode.go:19-51 re-implements the probe (exec, LookPath, Windows shim parsing). internal/plugin already probes through s.run(ctx, target, "--version"). opencode_npm.go, testdata/opencode-npm.cmd and the new Windows CI step exist only for this second copy. One shared, cached probe would remove them.
  • OpenCode special cases are spread across six files. target == "opencode" checks appear in native.go, plan.go, inventory.go, accounts.go, model.go and render.go. The recordHome/recordDir heuristics guess package roots from path names. Two alternatives: a per-target hook on TargetDef, or recording the package root on the record when it is written.
  • TargetPackage carries two unexported error fields. openCodeV1Error and openCodeV2Error feed a "pick v1 or v2 problem" block that is duplicated in service.go.
  • Small leftovers:
    • openCodeKey and fileURL are now one-line wrappers.
    • helpers_test.go:28 hard-wires OpenCodeVersion into every hooks test.

Happy to discuss any of these. The probe failure in Correctness 1 is the main thing I'd want resolved before merge.

@runkids runkids added the bug Something isn't working label Nov 15, 2026
…r agents

Review of the v2 directory package change found that one failed
`opencode --version` probe failed the whole hooks plan, so a machine
without the binary (a second machine sharing the config, CI, a
devcontainer) could no longer sync hooks to any agent, and doctor and
the dashboard preview failed with it.

Hooks:
- A probe that fails or reports an unknown major now skips only the
  OpenCode bindings with one warning per target. Outputs already owned
  there are parked, so they are neither rewritten nor removed while the
  layout is unknown. The probe runs once per plan, list and import.
- A `package` binding on OpenCode v1 is skipped with a warning instead
  of failing the plan.
- The v2 dependency warning is reported once, and only when a package
  file is written, so a synced hook no longer keeps doctor yellow.
- `hooks import` reports an unreadable file such as a symlink as that
  package's problem; other packages and flat files stay importable.
  The package validation problem is reported once instead of twice.
- Directories under `plugins/` are listed as unmanaged only on v2.

Plugins:
- The inventory leaves `plugins/skillshare-NAME` registrations to
  hooks, so a synced v2 hook is not offered as an importable plugin.

Dashboard: the new warnings are translated in every locale, a
`hook NAME:` prefix no longer defeats translation, the native preview
translates its per-file error, and the YAML editor documents `package`.

Docs: the English pages and the built-in skill describe the behavior
above; the ja, ko, zh-Hans and zh-Hant pages now carry the same
content as the English ones. The runbook drives the CLI with mdproof
assertions instead of prose expectations.

Refs runkids#913.
@runkids

runkids commented Nov 15, 2026

Copy link
Copy Markdown
Owner

I pushed 65a8ffa to this branch to address the review above. The main change: a failed or unrecognized opencode --version probe now skips only the OpenCode bindings with a warning and leaves existing OpenCode output untouched, so other agents keep syncing. It also covers the symlink import case, the hooks/plugins overlap in opencode.json, the doctor warning, v1 directory listing, dashboard translations, the translated docs and the runbook. The cleanup items are left for a follow-up. Thanks again for the work on this.

@runkids

runkids commented Nov 15, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 65a8ffaf46

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@runkids
runkids merged commit 43059a1 into runkids:main Nov 15, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants