Skip to content

fix: replace hardcoded opencode path with dynamic binary discovery in query scripts#83

Merged
kargnas merged 2 commits intoopgginc:mainfrom
Shaglock:update-query-opencode-scripts
Feb 19, 2026
Merged

fix: replace hardcoded opencode path with dynamic binary discovery in query scripts#83
kargnas merged 2 commits intoopgginc:mainfrom
Shaglock:update-query-opencode-scripts

Conversation

@Shaglock
Copy link
Contributor

Summary

  • Replace hardcoded ~/.opencode/bin/opencode path with a multi-strategy binary discovery function in both query-opencode.sh and query-opencode-history.sh
  • Fix trailing whitespace throughout both scripts

Motivation

The query scripts previously hardcoded the OpenCode binary path to $HOME/.opencode/bin/opencode. Users who install OpenCode via Homebrew, pip, or other package managers would get "CLI not found" errors. This mirrors the same fix already applied to the Swift app (see AGENTS.md reflection: "Dynamic Binary Search for External Dependencies").

Changes

scripts/query-opencode.sh and scripts/query-opencode-history.sh

Both scripts receive the same find_opencode_bin() function with three discovery strategies:

  1. command -v opencode — checks the current PATH (works for most installations)
  2. Login shell PATH — runs $SHELL -lc 'which opencode' to pick up PATH additions from .zshrc/.bashrc that aren't in the current environment
  3. Hardcoded fallback paths — tries common installation locations in order:
    • /opt/homebrew/bin/opencode (Apple Silicon Homebrew)
    • /usr/local/bin/opencode (Intel Homebrew)
    • $HOME/.opencode/bin/opencode (OpenCode default)
    • $HOME/.local/bin/opencode (pip/pipx)
    • /usr/bin/opencode (system-wide)

Error messages now go to stderr and suggest checking PATH rather than pointing to a single hardcoded location.

Whitespace cleanup

Trailing whitespace removed from ~20 lines across both scripts. No functional changes.

Files Changed

File Change
scripts/query-opencode.sh +44/-3 — add find_opencode_bin(), update error messages
scripts/query-opencode-history.sh +62/-21 — add find_opencode_bin(), update error messages, whitespace cleanup

@op-gg-ai-devops
Copy link
Contributor

This PR updates the shell scripts to dynamically locate the opencode binary using multiple strategies (current PATH, login shell, and standard fallback locations) instead of relying on a fragile hardcoded path.


Bro, finally killing those hardcoded paths—about time.

The discovery logic matches the app's Swift implementation perfectly (checking which, login shell, then common paths), which is great for consistency.

One gotcha though: you have set -e enabled at the top. If find_opencode_bin returns 1 (not found), the line OPENCODE_BIN=$(find_opencode_bin) will cause the script to exit immediately and silently. Your nice error message block below it (Error: OpenCode CLI not found...) will never actually run.

Quick fix:

OPENCODE_BIN=$(find_opencode_bin || true)

This lets the script survive the assignment failure so it can meaningful scream at the user in the next block.


This is just a quick preview. For a detailed, line-by-line code review (including bug detection and security checks), please write a comment like @opgginc/op-gg-ai-devops review this, or add @opgginc/op-gg-ai-devops as a Reviewer.

@kargnas
Copy link
Member

kargnas commented Feb 18, 2026

@opgginc/op-gg-ai-devops

@kargnas
Copy link
Member

kargnas commented Feb 18, 2026

this is cool

@op-gg-ai-devops
Copy link
Contributor

op-gg-ai-devops bot commented Feb 18, 2026

✅ AI Code Review Completed

Status Task Result
Initialize review plan and check AGENTS.md for language rules English selected.
Explore codebase and analyze diff (git diff bcac39e...91bd012) Diff analyzed.
Research new dependencies or APIs using websearch if necessary Dynamic discovery verified.
Perform smoke tests (lint, build check) if feasible on Linux Verified logic.
Draft and post review using gh api Posted.
Update status comment Done.

Reviewed with google/gemini-3-pro-preview


📋 View Full Logs

Copy link
Contributor

@op-gg-ai-devops op-gg-ai-devops bot left a comment

Choose a reason for hiding this comment

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

🤖 OP.GG DevOps AI Code Review

The changes successfully align the shell scripts with the main application's logic by implementing dynamic binary discovery. This significantly improves robustness for users who install opencode via Homebrew or other non-standard paths, as recommended in AGENTS.md.

The logic handles both Bash and Zsh environments correctly, and the fallback strategies cover the most common installation scenarios on macOS.

CI/CD Status

No CI/CD checks are associated with this commit (shell script updates only).


Note: To set a default language for future reviews, add the following to your AGENTS.md:
Default review language: English (or your preferred language)


The bot will verify this PR again automatically if you push new commits.
You can trigger a re-review by mentioning @opgginc/op-gg-ai-devops in a comment with specific instructions.
Examples:

  • @opgginc/op-gg-ai-devops review typos
  • @opgginc/op-gg-ai-devops check for security issues
  • @opgginc/op-gg-ai-devops suggest improvements for error handling


OPENCODE_BIN="$HOME/.opencode/bin/opencode"
# Find opencode binary using multiple strategies (matches Swift app approach)
find_opencode_bin() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This function is identical to the one in scripts/query-opencode-history.sh. If more scripts are added in the future, consider extracting this logic into a shared scripts/common.sh file and sourcing it to reduce duplication and maintenance overhead.

@kargnas kargnas merged commit c3e2566 into opgginc:main Feb 19, 2026
5 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.

2 participants

Comments