Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 36 additions & 17 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ print_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1"; }
print_error() { echo -e "${RED}[ERROR]${NC} $1"; }

# Find OpenCode config file (checks multiple possible locations)
# Returns: path to config file, or empty string if not found
find_opencode_config() {
local candidates=(
"$HOME/.config/opencode/opencode.json" # XDG standard (Linux, some macOS)
"$HOME/.opencode/opencode.json" # Alternative location
"$HOME/Library/Application Support/opencode/opencode.json" # macOS standard
)
for candidate in "${candidates[@]}"; do
if [[ -f "$candidate" ]]; then
echo "$candidate"
return 0
fi
done
return 1
}

# Find best python3 binary (prefer Homebrew/pyenv over system)
find_python3() {
local candidates=(
Expand Down Expand Up @@ -174,7 +191,8 @@ cleanup_deprecated_paths() {
# Remove deprecated MCP entries from opencode.json
# These MCPs have been replaced by curl-based subagents (zero context cost)
cleanup_deprecated_mcps() {
local opencode_config="$HOME/.config/opencode/opencode.json"
local opencode_config
opencode_config=$(find_opencode_config) || return 0

if [[ ! -f "$opencode_config" ]]; then
return 0
Expand Down Expand Up @@ -309,7 +327,8 @@ cleanup_deprecated_mcps() {
# - google-analytics-mcp: ~800 tokens - enable via @google-analytics subagent
# - context7: ~800 tokens - enable via @context7 subagent (for library docs lookup)
disable_ondemand_mcps() {
local opencode_config="$HOME/.config/opencode/opencode.json"
local opencode_config
opencode_config=$(find_opencode_config) || return 0

if [[ ! -f "$opencode_config" ]]; then
return 0
Expand Down Expand Up @@ -2053,13 +2072,14 @@ inject_agents_reference() {
update_opencode_config() {
print_info "Updating OpenCode configuration..."

local opencode_config="$HOME/.config/opencode/opencode.json"

if [[ ! -f "$opencode_config" ]]; then
print_info "OpenCode config not found at $opencode_config - skipping"
local opencode_config
if ! opencode_config=$(find_opencode_config); then
print_info "OpenCode config not found (checked ~/.config/opencode/, ~/.opencode/, ~/Library/Application Support/opencode/) - skipping"
return 0
fi

print_info "Found OpenCode config at: $opencode_config"

Comment on lines +2075 to +2082
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.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# First, find all generator scripts that might reference opencode
find . -name "generate-opencode*.sh" -o -name "*generate*opencode*.sh" | head -20

Repository: marcusquinn/aidevops

Length of output: 155


🏁 Script executed:

#!/bin/bash
# Search for hardcoded opencode.json and config paths in all shell scripts
rg -n "opencode\.json|\.config/opencode|OPENCODE_CONFIG" --type sh | grep -i "generate\|script" | head -30

Repository: marcusquinn/aidevops

Length of output: 3235


🏁 Script executed:

#!/bin/bash
# Get more context on update_opencode_config and how config path is passed to generators
rg -B 5 -A 15 "update_opencode_config" setup.sh

Repository: marcusquinn/aidevops

Length of output: 2380


Generator scripts hardcode OpenCode config path—non-standard installs will fail.

update_opencode_config() dynamically discovers the config location, but generate-opencode-agents.sh (lines 23–25) and generate-opencode-commands.sh (line 18) hardcode $HOME/.config/opencode/. This breaks installs with configs at ~/.opencode/ or ~/Library/Application Support/opencode/.

The generator scripts must accept the discovered config path as a parameter (e.g., OPENCODE_CONFIG environment variable or argument) instead of assuming a fixed location.

🤖 Prompt for AI Agents
In `@setup.sh` around lines 2075 - 2082, The generator scripts hardcode
$HOME/.config/opencode; change generate-opencode-agents.sh and
generate-opencode-commands.sh to accept the discovered config path via an
OPENCODE_CONFIG environment variable or a command argument (falling back to
current default only if OPENCODE_CONFIG is unset), and update callers to pass
the path returned by update_opencode_config()/find_opencode_config (the
opencode_config local variable shown in the diff) instead of assuming
~/.config/opencode; ensure the scripts use OPENCODE_CONFIG when present to
locate files and preserve existing behavior when it is not set.

# Create backup (with rotation)
create_backup_with_rotation "$opencode_config" "opencode"

Expand Down Expand Up @@ -2324,7 +2344,8 @@ resolve_mcp_binary_path() {
# Update opencode.json MCP commands to use full binary paths
# This ensures MCPs start regardless of PATH configuration
update_mcp_paths_in_opencode() {
local opencode_config="$HOME/.config/opencode/opencode.json"
local opencode_config
opencode_config=$(find_opencode_config) || return 0

if [[ ! -f "$opencode_config" ]]; then
return 0
Expand Down Expand Up @@ -2908,8 +2929,6 @@ add_opencode_plugin() {
setup_opencode_plugins() {
print_info "Setting up OpenCode plugins..."

local opencode_config="$HOME/.config/opencode/opencode.json"

# Check if OpenCode is installed
if ! command -v opencode &> /dev/null; then
print_warning "OpenCode not found - plugin setup skipped"
Expand All @@ -2918,8 +2937,9 @@ setup_opencode_plugins() {
fi

# Check if config exists
if [[ ! -f "$opencode_config" ]]; then
print_warning "OpenCode config not found at $opencode_config - plugin setup skipped"
local opencode_config
if ! opencode_config=$(find_opencode_config); then
print_warning "OpenCode config not found - plugin setup skipped"
return 0
fi

Expand Down Expand Up @@ -2961,16 +2981,15 @@ setup_opencode_plugins() {
setup_oh_my_opencode() {
print_info "Setting up Oh-My-OpenCode plugin..."

local opencode_config="$HOME/.config/opencode/opencode.json"

# Check if OpenCode is installed
if ! command -v opencode &> /dev/null; then
print_warning "OpenCode not found - Oh-My-OpenCode setup skipped"
return 0
fi

# Check if config exists
if [[ ! -f "$opencode_config" ]]; then
local opencode_config
if ! opencode_config=$(find_opencode_config); then
print_warning "OpenCode config not found - Oh-My-OpenCode setup skipped"
return 0
fi
Expand Down Expand Up @@ -3106,12 +3125,12 @@ setup_seo_mcps() {
setup_google_analytics_mcp() {
print_info "Setting up Google Analytics MCP..."

local opencode_config="$HOME/.config/opencode/opencode.json"
local gsc_creds="$HOME/.config/aidevops/gsc-credentials.json"

# Check if opencode.json exists
if [[ ! -f "$opencode_config" ]]; then
print_warning "OpenCode config not found at $opencode_config - skipping Google Analytics MCP"
local opencode_config
if ! opencode_config=$(find_opencode_config); then
print_warning "OpenCode config not found - skipping Google Analytics MCP"
return 0
fi

Expand Down
Loading