Repository navigation
feat(opencode): add OpenCode integration (activity tracking, plugin, config) - #1807
Conversation
worktrunk-bot
left a comment
There was a problem hiding this comment.
Well-structured PR that follows existing patterns nicely — the plugin design, CLI structure, config show integration, and test coverage for the show command all look solid. A few observations:
Testing gap: handle_opencode_install and handle_opencode_uninstall (~80 lines in src/commands/config/opencode.rs) have no direct test coverage. The --yes flag makes non-interactive testing feasible — tests like "install writes plugin to expected path", "install is idempotent", "uninstall removes file", "uninstall when not installed" would cover the core logic. This will likely trigger codecov/patch.
Unrelated changes: The sort_by → sort_by_key refactor in branches.rs:233 and the thread ID snapshot filter in hook_show.rs:302 are unrelated to OpenCode integration. Consider splitting these into a separate commit or PR for cleaner history.
worktrunk-bot
left a comment
There was a problem hiding this comment.
CI failed on all three platforms with three distinct test failures:
1. test_error_with_context_formatting — Git version mismatch between the author's machine and CI. The snapshot expects:
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
But CI's git produces:
fatal: not a git repository (or any of the parent directories): .git
(Git 2.45+ changed this message format.)
2. test_hook_show_outside_git_repo — The snapshot expects exit code 101 (panic) with thread/backtrace output, but the actual behavior is exit code 1 with a formatted error message. The snapshot needs regenerating against the current code.
3. test_command_pages_and_skill_files_are_in_sync — Doc pages are out of sync with CLI help text. After adding the opencode subcommand and its after_long_help text, cargo test --test integration test_command_pages_and_skill_files_are_in_sync needs to be run to regenerate the synced files.
Fix: Regenerate snapshots and sync docs in the CI environment:
cargo insta test --accept -- --test integration "test_help"
cargo insta test --accept -- --test integration "test_error_with_context_formatting"
cargo insta test --accept -- --test integration "test_hook_show_outside_git_repo"
cargo test --test integration test_command_pages_and_skill_files_are_in_sync8eae00b to
8cbe67b
Compare
|
Addressing review feedback: The unrelated changes flagged by worktrunk-bot have been extracted into separate PRs:
This PR now includes both as ancestor commits so CI passes. Once #1808 and #1809 are merged, this branch will be rebased onto Additional changes in this update:
|
|
Thanks for the thorough follow-up! Both concerns are addressed:
I'll take another look once those ancestor PRs are merged and this is rebased onto |
CI failed on macOS and Windows — platform-specific config directory paths
worktrunk-bot
left a comment
There was a problem hiding this comment.
CI failed on macOS (6 tests) and Windows (6 tests) — all OpenCode-related snapshot failures caused by platform-specific config directory paths.
Root cause: opencode_plugins_dir() falls back to dirs::config_dir() which returns platform-specific paths:
- Linux:
~/.config/opencode/plugins/ - macOS:
~/Library/Application Support/opencode/plugins/ - Windows:
C:\Users\<user>\AppData\Roaming\opencode\plugins\
The snapshots were generated on Linux. The test helper setup_opencode_plugin_installed() hardcodes .config/opencode/plugins — so on macOS/Windows the code looks in one place while the helper writes to another, causing "Plugin not installed" instead of the expected output.
Fix: Set OPENCODE_CONFIG_DIR env var in all OpenCode tests to force a deterministic path regardless of platform. This bypasses dirs::config_dir() entirely and uses the override path built into opencode_plugins_dir().
Concretely:
- In
setup_opencode_plugin_installed(), write to a path liketemp_home.join("opencode-config/plugins")instead oftemp_home.join(".config/opencode/plugins") - Add
cmd.env("OPENCODE_CONFIG_DIR", temp_home.path().join("opencode-config"))toconfigure_wt_cmd()(or each test), so both the helper and the production code resolve to the same location - Regenerate snapshots — they'll now show the
OPENCODE_CONFIG_DIR-based path consistently across platforms
The existing Claude Code tests avoid this issue because they use WORKTRUNK_TEST_CLAUDE_INSTALLED to skip the which check and set_xdg_config_path which controls XDG_CONFIG_HOME — but the Claude plugin uses a different install mechanism (claude plugin install) that doesn't write files to dirs::config_dir().
8cbe67b to
c86a71d
Compare
worktrunk-bot
left a comment
There was a problem hiding this comment.
The cross-platform test failure from the previous CI run (macOS and Windows) is still present — OPENCODE_CONFIG_DIR is not set in any tests. dirs::config_dir() returns ~/Library/Application Support on macOS and AppData\Roaming on Windows, so opencode_plugins_dir() resolves to a different path than the .config/opencode/plugins hardcoded in setup_opencode_plugin_installed() and the install test assertions.
Fix: set OPENCODE_CONFIG_DIR env var in all OpenCode tests to force a deterministic path. The env var override is already built into opencode_plugins_dir() — the tests just need to use it.
c86a71d to
5cf5614
Compare
worktrunk-bot
left a comment
There was a problem hiding this comment.
codecov/patch failed: 75.75% patch coverage vs 95.54% target.
The gap is primarily in src/commands/config/opencode.rs — the interactive prompt paths in handle_opencode_install (lines 76–90) and handle_opencode_uninstall (lines 128–142) are untested because the tests all pass --yes. There's also the dirs::config_dir() fallback (lines 26–28), which is intentionally bypassed via OPENCODE_CONFIG_DIR for cross-platform reliability.
The prompt pattern is the same one used in configure_shell.rs and update.rs, but those existing functions may already be covered or grandfathered in. Options to close the gap:
- Extract the write/remove logic from the prompt branches so the core I/O is tested independently of the prompt. The prompt itself stays untested (acceptable), but the logic that runs after confirmation gets coverage through the
--yespath. - Add PTY-based tests for the interactive prompt flow (higher effort, probably not worth it for this).
Option 1 is essentially already the case — the --yes tests cover the same write/remove code paths. The issue is that codecov counts the prompt call sites and match arms as uncovered lines even though they're boilerplate. If the current structure can't reach the threshold, the simplest fix may be collapsing the prompt logic to reduce line count (e.g., early-return style instead of match arms).
codecov/patch failed (75.75% vs 95.54% target) — interactive prompt paths in opencode.rs lack coverage
5cf5614 to
cb81674
Compare
worktrunk-bot
left a comment
There was a problem hiding this comment.
Minor naming observation — the other tools use branded display names ("Claude Code", "Codex") but OpenCode uses the CLI binary name. Low priority since display_name() only appears in the commit generation prompt.
codecov/patch failed — uncovered lines in opencode.rs prompt paths
worktrunk-bot
left a comment
There was a problem hiding this comment.
codecov/patch failed — the interactive prompt branches in handle_opencode_install (lines 76–88) and handle_opencode_uninstall (lines 125–137) are uncovered because all tests use --yes. The dirs::config_dir() fallback (line 26–28) is also uncovered since tests set OPENCODE_CONFIG_DIR.
The simplest fix is to restructure the prompt logic to reduce uncovered line count — using early-return style collapses the match arms. This is the same pattern the previous review suggested:
handle_opencode_install (lines 75–88 → early return):
// Prompt for confirmation (skipped with --yes)
if !yes {
let response = prompt_yes_no_preview(
&cformat!("{action} OpenCode plugin @ <bold>{target_display}</>?"),
|| eprintln!("{}", info_message(cformat!("Would write to <bold>{target_display}</>"))),
)?;
if response == PromptResponse::Declined {
return Ok(());
}
}Same pattern for handle_opencode_uninstall. This reduces the uncovered surface from multi-line closure + match to a simpler structure. The dirs::config_dir() fallback is acceptable since it's intentionally bypassed for cross-platform reliability.
85d288d to
2191273
Compare
94f89f0 to
1b1c35f
Compare
CI failed — test_opencode_install_uses_dirs_fallback fails on macOS and Windows
worktrunk-bot
left a comment
There was a problem hiding this comment.
CI failed on macOS and Windows — both fail on test_opencode_install_uses_dirs_fallback.
Root cause: The test removes OPENCODE_CONFIG_DIR to exercise the dirs::config_dir() fallback, but dirs::config_dir() resolves differently per platform:
- Linux: Uses
XDG_CONFIG_HOME(set by test) →{temp_home}/.config— works - macOS: Uses
$HOME/Library/Application Support(ignoresXDG_CONFIG_HOME) → different path than snapshot - Windows: Uses
SHGetKnownFolderPath(native API, ignoresAPPDATAenv var) → returns the real system path, not the test path →dirs::config_dir()likely returnsNonein the test sandbox → "Could not determine config directory"
The snapshot was generated on Linux. The simplest fix is gating this test to Linux only, since the dirs::config_dir() fallback is inherently platform-specific and the other install tests (which use OPENCODE_CONFIG_DIR) already cover the core logic cross-platform.
6a5f0c4 to
263839d
Compare
263839d to
ddefcfa
Compare
# Conflicts: # skills/worktrunk/reference/config.md
Remove dedicated docs page and README/landing page mentions. OpenCode is now discoverable via `wt config show` (when opencode is on PATH), the `.opencode-plugin/` directory, and a mention in tips-patterns — but no nav entry or top billing. Co-Authored-By: Claude <[email protected]>
|
thank you @noirbizarre ! overall it looks good; thank you for contributing! because we're literally just starting out, I'm going to reduce the prominence of the docs a bit. the current PR has a link to this on the worktrunk home page... if folks start using this more, I'm happy to increase its prominence again |
# Conflicts: # tests/snapshots/integration__integration_tests__config_show__config_show_always_regenerates_migration_file.snap # tests/snapshots/integration__integration_tests__config_show__config_show_displays_deprecation_details.snap # tests/snapshots/integration__integration_tests__config_show__config_show_displays_project_commit_generation_deprecations.snap # tests/snapshots/integration__integration_tests__config_show__config_show_empty_project_config.snap # tests/snapshots/integration__integration_tests__config_show__config_show_empty_system_config.snap # tests/snapshots/integration__integration_tests__config_show__config_show_fish_outdated_wrapper.snap # tests/snapshots/integration__integration_tests__config_show__config_show_fish_with_completions.snap # tests/snapshots/integration__integration_tests__config_show__config_show_fish_without_completions.snap # tests/snapshots/integration__integration_tests__config_show__config_show_from_linked_worktree_shows_main_worktree_hint.snap # tests/snapshots/integration__integration_tests__config_show__config_show_full_command_not_found.snap # tests/snapshots/integration__integration_tests__config_show__config_show_full_not_configured.snap # tests/snapshots/integration__integration_tests__config_show__config_show_full_update_available.snap # tests/snapshots/integration__integration_tests__config_show__config_show_full_version_check_unavailable.snap # tests/snapshots/integration__integration_tests__config_show__config_show_github_remote.snap # tests/snapshots/integration__integration_tests__config_show__config_show_gitlab_remote.snap # tests/snapshots/integration__integration_tests__config_show__config_show_invalid_project_toml.snap # tests/snapshots/integration__integration_tests__config_show__config_show_invalid_system_config.snap # tests/snapshots/integration__integration_tests__config_show__config_show_invalid_user_toml.snap # tests/snapshots/integration__integration_tests__config_show__config_show_no_project_config.snap # tests/snapshots/integration__integration_tests__config_show__config_show_no_user_config.snap # tests/snapshots/integration__integration_tests__config_show__config_show_nushell_outdated_wrapper.snap # tests/snapshots/integration__integration_tests__config_show__config_show_outside_git_repo.snap # tests/snapshots/integration__integration_tests__config_show__config_show_partial_shell_config_shows_hint.snap # tests/snapshots/integration__integration_tests__config_show__config_show_powershell_detected_via_psmodulepath.snap # tests/snapshots/integration__integration_tests__config_show__config_show_shell_integration_active.snap # tests/snapshots/integration__integration_tests__config_show__config_show_suggests_project_config_for_ci.snap # tests/snapshots/integration__integration_tests__config_show__config_show_suggests_user_config_for_commit_generation.snap # tests/snapshots/integration__integration_tests__config_show__config_show_unmatched_candidate_not_suppressed_by_wrapper.snap # tests/snapshots/integration__integration_tests__config_show__config_show_unmatched_candidate_warning.snap # tests/snapshots/integration__integration_tests__config_show__config_show_warns_unknown_project_keys.snap # tests/snapshots/integration__integration_tests__config_show__config_show_warns_unknown_user_keys.snap # tests/snapshots/integration__integration_tests__config_show__config_show_whitespace_only_project_config.snap # tests/snapshots/integration__integration_tests__config_show__config_show_with_project_config.snap # tests/snapshots/integration__integration_tests__config_show__config_show_with_system_config.snap # tests/snapshots/integration__integration_tests__config_show__config_show_zsh_compinit_correct_order.snap # tests/snapshots/integration__integration_tests__config_show__config_show_zsh_compinit_warning.snap # tests/snapshots/integration__integration_tests__configure_shell__config_show_detects_fish_legacy_conf_d.snap # tests/snapshots/integration__integration_tests__configure_shell__config_show_fish_legacy_with_functions_dir.snap
worktrunk-bot
left a comment
There was a problem hiding this comment.
The OpenCode integration follows existing patterns well — plugin structure mirrors Claude Code's, tests cover the key paths (install, idempotent, update, uninstall, prompt decline, dirs fallback), and cross-platform issues from earlier rounds are resolved.
One issue: the OPENCODE section in config show renders unconditionally, while the CLAUDE CODE section is gated behind is_claude_available(). This means every user who doesn't have opencode installed sees an "opencode CLI not installed" line — which is noisy and contradicts the stated goal of keeping OpenCode low-profile until adoption grows.
# Conflicts: # docs/content/config.md # skills/worktrunk/reference/config.md # src/cli/mod.rs # src/commands/config/mod.rs # src/commands/mod.rs # src/main.rs # tests/common/mod.rs # tests/snapshots/integration__integration_tests__help__help_config_long.snap # tests/snapshots/integration__integration_tests__help__help_config_short.snap
Gate render_opencode_status() behind is_opencode_available() check, matching the Claude Code pattern. Also apply cargo fmt. Co-Authored-By: Claude <[email protected]>
# Conflicts: # src/commands/config/mod.rs # src/commands/mod.rs # src/main.rs
Co-Authored-By: Claude <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
CI failed on Linux and macOS with test_project_config_docs_include_all_sections — this is a pre-existing failure on main introduced by #1844, not caused by this PR. The test expects bare hook keys (e.g., pre-switch) between PROJECT_CONFIG_START/PROJECT_CONFIG_END markers in src/cli/mod.rs, but the refactored ## Hooks section references wt hook --help without listing example hook keys.
Windows passed. The OpenCode-specific tests all pass on all platforms.
Move OpenCode install/uninstall from top-level `wt config opencode` to `wt config plugins opencode`, consistent with Claude Code's `wt config plugins claude`. Update all help text, hints, tests, and docs references. Co-Authored-By: Claude <[email protected]>
Follows existing pattern — `dev/` already holds embedded assets (`config.example.toml`, `wt.example.toml`). Removes dotdir from repo root. Co-Authored-By: Claude <[email protected]>
|
Hi 👋🏻 I just seen drafted release notes for the next release and that all the plugin logic has been extracted for Claude (I'm glad you did, I use both), but despite the updates and the Are you not intending to merge it? Do you require some updates from me on this branch? (I did not performed any update as I saw you work on it so I preferred not to interfer and risk slow you down by creating more conflict but don't hesitate to ping me if you require any change) |
dev/opencode-plugin.ts is on main now (#1807), so the link check exclusion is no longer needed. > _This was written by Claude Code on behalf of @max-sixty_ Co-authored-by: Claude <[email protected]>
This PR adds OpenCode integration: activity tracking markers in
wt list, plugin installation via CLI,wt config showdiagnostics, and LLM commit generation detection.Continues the work started in #1295 and #1533 which added OpenCode to the docs and example config.
What's included
dev/opencode-plugin.ts): mapssession.status/session.idle/session.deletedto branch markers, same pattern as Claude Code's pluginwt config plugins opencode install/uninstall: installs the plugin to~/.config/opencode/plugins/worktrunk.ts— source embedded viainclude_str!(), no npm needed. Sits underwt config pluginsalongside Claude Code'swt config plugins claude.wt config showOPENCODE section: shows plugin install status with actionable hints (only whenopencodeis on PATH)LlmTool::OpenCodevariant: detected via PATH for commit generation auto-configDocs approach
Kept deliberately low-profile — no dedicated docs page, no README mention. OpenCode is discoverable via
wt config showand a mention in tips-patterns. If it becomes popular, docs prominence can increase.