Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ enum AgentHookInstaller {
content: buildCopilotCliWrapper()
)

ensureFile(
url: AgentStatusPaths.opencodeWrapperPath,
mode: 0o755,
marker: wrapperMarker,
content: buildOpenCodeWrapper()
)

ensureFile(
url: AgentStatusPaths.opencodeGlobalPluginPath,
mode: 0o644,
Expand Down Expand Up @@ -209,7 +216,7 @@ enum AgentHookInstaller {
if [ -x /usr/libexec/path_helper ]; then
eval "$(/usr/libexec/path_helper -s)" 2>/dev/null
fi
for _d in "$HOME/.local/bin" "$HOME/.bun/bin" "/opt/homebrew/bin" "/opt/homebrew/sbin" "/usr/local/bin" "$HOME/.cargo/bin"; do
for _d in "$HOME/.local/bin" "$HOME/.bun/bin" "$HOME/.opencode/bin" "/opt/homebrew/bin" "/opt/homebrew/sbin" "/usr/local/bin" "$HOME/.cargo/bin"; do
if [ -d "$_d" ]; then
case ":$PATH:" in
*":$_d:"*) ;;
Expand Down Expand Up @@ -356,6 +363,42 @@ enum AgentHookInstaller {
"""
}

private static func buildOpenCodeWrapper() -> String {
let binDir = AgentStatusPaths.binDir.path
return """
#!/bin/bash
\(wrapperMarker)
# Wrapper for OpenCode: ensures PATH includes common install locations.

\(pathAugmentSnippet())

find_real_binary() {
local name="$1"
local IFS=:
for dir in $PATH; do
[ -z "$dir" ] && continue
dir="${dir%/}"
if [ "$dir" = "\(binDir)" ]; then
continue
fi
if [ -x "$dir/$name" ] && [ ! -d "$dir/$name" ]; then
printf "%s\\n" "$dir/$name"
return 0
fi
done
return 1
}

REAL_BIN="$(find_real_binary "opencode")"
if [ -z "$REAL_BIN" ]; then
echo "Ghostree: opencode not found in PATH. Install it and ensure it is on PATH, then retry." >&2
exit 127
fi

exec "$REAL_BIN" "$@"
"""
}

private static func buildOpenCodePlugin() -> String {
let marker = AgentStatusPaths.opencodePluginMarker
return """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ enum AgentStatusPaths {
binDir.appendingPathComponent("copilot")
}

static var opencodeWrapperPath: URL {
binDir.appendingPathComponent("opencode")
}

static var opencodePluginMarker: String { "// Ghostree opencode plugin v5" }

/** @see https://opencode.ai/docs/plugins */
Expand Down
3 changes: 2 additions & 1 deletion macos/Sources/Features/Worktrunk/WorktrunkPreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ enum WorktrunkAgent: String, CaseIterable, Identifiable {

private static func searchPaths(excluding excludedPath: String) -> [String] {
var paths: [String] = []
let prefix = ["/opt/homebrew/bin", "/usr/local/bin"]
let home = FileManager.default.homeDirectoryForCurrentUser.path
let prefix = ["/opt/homebrew/bin", "/usr/local/bin", "\(home)/.opencode/bin"]
let existingPath = ProcessInfo.processInfo.environment["PATH"] ?? ""
let existingComponents = existingPath.split(separator: ":").map(String.init)

Expand Down
Loading