Skip to content

feat(opencode): add OpenCode integration (activity tracking, plugin, config) - #1807

Merged
max-sixty merged 12 commits into
max-sixty:mainfrom
noirbizarre:feat/opencode-ingration
Apr 6, 2026
Merged

max-sixty merged 12 commits into
max-sixty:mainfrom
noirbizarre:feat/opencode-ingration

Conversation

@noirbizarre

@noirbizarre noirbizarre commented Mar 30, 2026 •

Copy link
Copy Markdown
Contributor

This PR adds OpenCode integration: activity tracking markers in wt list, plugin installation via CLI, wt config show diagnostics, 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

  • Activity tracking plugin (dev/opencode-plugin.ts): maps session.status/session.idle/session.deleted to branch markers, same pattern as Claude Code's plugin
  • wt config plugins opencode install/uninstall: installs the plugin to ~/.config/opencode/plugins/worktrunk.ts — source embedded via include_str!(), no npm needed. Sits under wt config plugins alongside Claude Code's wt config plugins claude.
  • wt config show OPENCODE section: shows plugin install status with actionable hints (only when opencode is on PATH)
  • LlmTool::OpenCode variant: detected via PATH for commit generation auto-config

Docs approach

Kept deliberately low-profile — no dedicated docs page, no README mention. OpenCode is discoverable via wt config show and a mention in tips-patterns. If it becomes popular, docs prominence can increase.

This was written by Claude Code on behalf of @max-sixty

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Comment thread src/commands/config/opencode.rs Resolved
Comment thread src/git/repository/branches.rs Resolved

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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_sync

@noirbizarre

Copy link
Copy Markdown
Contributor Author

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 main to remove those commits.

Additional changes in this update:

  • Added 5 install/uninstall integration tests (test_opencode_install_creates_plugin, test_opencode_install_already_installed, test_opencode_install_updates_outdated, test_opencode_uninstall_removes_plugin, test_opencode_uninstall_not_installed) to cover the handle_opencode_install/handle_opencode_uninstall functions and address the codecov/patch gap
  • Fixed doc sync for skills/worktrunk/reference/opencode.md

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

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 main.

worktrunk-bot
worktrunk-bot previously approved these changes Mar 30, 2026
@worktrunk-bot
worktrunk-bot dismissed their stale review March 30, 2026 12:36

CI failed on macOS and Windows — platform-specific config directory paths

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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:

  1. In setup_opencode_plugin_installed(), write to a path like temp_home.join("opencode-config/plugins") instead of temp_home.join(".config/opencode/plugins")
  2. Add cmd.env("OPENCODE_CONFIG_DIR", temp_home.path().join("opencode-config")) to configure_wt_cmd() (or each test), so both the helper and the production code resolve to the same location
  3. 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().

@noirbizarre
noirbizarre force-pushed the feat/opencode-ingration branch from 8cbe67b to c86a71d Compare March 30, 2026 12:48

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Comment thread tests/common/mod.rs Resolved
@noirbizarre
noirbizarre force-pushed the feat/opencode-ingration branch from c86a71d to 5cf5614 Compare March 30, 2026 17:22
worktrunk-bot
worktrunk-bot previously approved these changes Mar 30, 2026

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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:

  1. 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 --yes path.
  2. 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).

@worktrunk-bot
worktrunk-bot dismissed their stale review March 30, 2026 17:44

codecov/patch failed (75.75% vs 95.54% target) — interactive prompt paths in opencode.rs lack coverage

@noirbizarre
noirbizarre force-pushed the feat/opencode-ingration branch from 5cf5614 to cb81674 Compare March 30, 2026 20:35
worktrunk-bot
worktrunk-bot previously approved these changes Mar 30, 2026

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Comment thread src/output/commit_generation.rs Resolved
@worktrunk-bot
worktrunk-bot dismissed their stale review March 30, 2026 20:48

codecov/patch failed — uncovered lines in opencode.rs prompt paths

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

@noirbizarre
noirbizarre force-pushed the feat/opencode-ingration branch 2 times, most recently from 85d288d to 2191273 Compare March 30, 2026 22:03
@noirbizarre
noirbizarre force-pushed the feat/opencode-ingration branch 2 times, most recently from 94f89f0 to 1b1c35f Compare March 30, 2026 22:54
worktrunk-bot
worktrunk-bot previously approved these changes Mar 30, 2026
@worktrunk-bot
worktrunk-bot dismissed their stale review March 30, 2026 23:07

CI failed — test_opencode_install_uses_dirs_fallback fails on macOS and Windows

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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 (ignores XDG_CONFIG_HOME) → different path than snapshot
  • Windows: Uses SHGetKnownFolderPath (native API, ignores APPDATA env var) → returns the real system path, not the test path → dirs::config_dir() likely returns None in 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.

Comment thread tests/integration_tests/config_show.rs Resolved
@noirbizarre
noirbizarre force-pushed the feat/opencode-ingration branch from 6a5f0c4 to 263839d Compare March 30, 2026 23:50
@noirbizarre
noirbizarre force-pushed the feat/opencode-ingration branch from 263839d to ddefcfa Compare March 31, 2026 00:03
max-sixty and others added 2 commits March 30, 2026 19:18
# 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]>
@max-sixty

Copy link
Copy Markdown
Owner

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 worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Comment thread src/commands/config/show.rs Resolved
max-sixty and others added 2 commits March 30, 2026 23:33
# 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]>
max-sixty and others added 2 commits March 31, 2026 18:29
# Conflicts:
#	src/commands/config/mod.rs
#	src/commands/mod.rs
#	src/main.rs
Co-Authored-By: Claude <[email protected]>

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

max-sixty and others added 2 commits April 1, 2026 13:38
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]>
@noirbizarre

Copy link
Copy Markdown
Contributor Author

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 main merges, this branch is not merged and not part of the release.

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)

@max-sixty
max-sixty merged commit 4ef64c4 into max-sixty:main Apr 6, 2026
22 checks passed
max-sixty added a commit that referenced this pull request Apr 6, 2026
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]>
@noirbizarre
noirbizarre deleted the feat/opencode-ingration branch April 6, 2026 19:56
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.

3 participants