Repository navigation
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📥 CommitsReviewing files that changed from the base of the PR and between d95cbb1912e80f0bd26785aa429dc2c82d3ae678 and 0cc003b90bb5d21ee400a86ed5d8145395f38b69. 📒 Files selected for processing (12)
🚧 Files skipped from review as they are similar to previous changes (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughAdded Severity of issue fixed: Medium Merge Risk: 🔵 Low · up to The fallback may treat an existing regular file as an OpenCode configuration directory, which could make configuration loading fail or behave incorrectly for affected users. The change is otherwise validated and appears mergeable with owner awareness of this edge case. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Taking a look! |
01dd83a to
285bbda
Compare
|
Rebased onto latest The conflict came from #9543 ( No logic changes from the version you started reviewing. Re-verified after the rebase: |
285bbda to
24c9e75
Compare
|
Thanks for the fix — I took this over and pushed a refined version. The default config source is now resolved from the actual PTY environment (including XDG/HOME and static shell exports) before reusing Orca's existing source-scoped overlay, so app/shell environment differences and nested Orca sessions keep the user's config while the status plugin remains installed. I also rebased onto current main and added focused coverage; 344 relevant tests, node typecheck, touched-file lint, and the max-lines gate all pass. |
|
@brennanb2025 Thanks again for taking the time to refine this and pushing the updates! I tested the latest version locally, and it seems to be working as expected. Is there anything else needed from my side before this can be merged? |
24c9e75 to
c848bc9
Compare
Greptile SummaryThis PR fixes a bug where OpenCode launched from Orca without
Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| src/main/opencode/config-source.ts | New module that resolves the default OpenCode config directory via XDG fallbacks; logic is correct and the bootstrap problem (can't pass XDG_CONFIG_HOME to discover itself for fish config) is handled acceptably. |
| src/main/ipc/pty/host-env/pi-agent.ts | Extends resolveOpenCodeSourceConfigDir to fall back to resolveDefaultOpenCodeConfigDir when no explicit config dir is found; the early-return guard structure is clean and preserves all existing paths. |
| src/main/opencode/config-source.test.ts | New test file with four well-scoped cases covering XDG precedence, HOME fallback, shell-startup probe (zsh), and the missing-dir guard; uses unique mkdtempSync roots to avoid cache collisions. |
| src/main/ipc/pty-ipc-mock-registry.ts | Adds openCodeConfigSourceModuleMock and resolveDefaultOpenCodeConfigDirMock; clean extension of the existing mock registry pattern. |
| src/main/ipc/pty-ipc-suite-environment.ts | Correctly resets resolveDefaultOpenCodeConfigDirMock and seeds it with undefined in the default env setup, preventing real ~/.config/opencode from influencing unrelated IPC tests. |
| src/main/ipc/pty-spawn-env-agent-overlays.test.ts | Adds the key integration regression test asserting that a resolved default config dir is forwarded to buildPtyEnv and reflected in ORCA_OPENCODE_SOURCE_CONFIG_DIR and OPENCODE_CONFIG_DIR. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[PTY spawn — OpenCode agent] --> B{OPENCODE_CONFIG_DIR set\nin PTY env or shell startup?}
B -- yes, Orca-owned overlay --> C[Return undefined\nno source mirror]
B -- yes, user-set --> D[Return explicit config dir\nas source for overlay]
B -- no --> E[resolveDefaultOpenCodeConfigDir]
E --> F{ptyEnv.XDG_CONFIG_HOME?}
F -- yes --> G[configHome = ptyEnv.XDG_CONFIG_HOME]
F -- no --> H{processEnv.XDG_CONFIG_HOME?}
H -- yes --> I[configHome = processEnv.XDG_CONFIG_HOME]
H -- no --> J[readShellStartupEnvVar XDG_CONFIG_HOME\nfrom shell startup files]
J --> K{Found in shell?}
K -- yes --> L[configHome = shell value]
K -- no --> M[configHome = HOME/.config]
G & I & L & M --> N[configDir = configHome/opencode]
N --> O{existsSync configDir?}
O -- yes --> P[Return configDir as source]
O -- no --> Q[Return undefined\nno mirror, bare shared/ dir]
P --> R[buildPtyEnv with sourceConfigDir\nmirrors user config into overlay]
D --> R
Q --> S[buildPtyEnv with no sourceConfigDir\nbare plugin dir only]
Reviews (3): Last reviewed commit: "fix(opencode): mirror default config whe..." | Re-trigger Greptile
c848bc9 to
c2190f8
Compare
c2190f8 to
cb32e11
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 7bc46d55-4826-4819-9e50-352f370db084
📥 Commits
Reviewing files that changed from the base of the PR and between dd63d35 and cb32e1184c6bf65b4c3cd957db76b7baf0e0dda3.
📒 Files selected for processing (4)
src/main/ipc/pty.test.tssrc/main/ipc/pty.tssrc/main/opencode/config-source.test.tssrc/main/opencode/config-source.ts
| readShellStartupEnvVar('XDG_CONFIG_HOME', home, shell) || | ||
| join(home, '.config') | ||
| const configDir = join(configHome, 'opencode') | ||
| return existsSync(configDir) ? configDir : undefined |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/sh
set -eu
rg -n -C 4 'resolveDefaultOpenCodeConfigDir|ORCA_OPENCODE_SOURCE_CONFIG_DIR|openCodeBuildPtyEnv' src/mainRepository: stablyai/orca
Length of output: 1941
🏁 Script executed:
#!/bin/sh
set -eu
printf '%s\n' '--- target file ---'
wc -l src/main/opencode/config-source.ts
cat -n src/main/opencode/config-source.ts
printf '%s\n' '--- related symbols and tests ---'
rg -n -C 5 'resolveDefaultOpenCodeConfigDir|ORCA_OPENCODE_SOURCE_CONFIG_DIR|openCodeBuildPtyEnv|config-source' src/main src/renderer test tests 2>/dev/null || trueRepository: stablyai/orca
Length of output: 1912
🌐 Web query:
stablyai/orca src/main/opencode/config-source.ts resolveDefaultOpenCodeConfigDir
💡 Result:
In the context of the stablyai/orca repository, resolveDefaultOpenCodeConfigDir is a utility function responsible for determining the default directory for OpenCode configuration files. While specific implementation details can evolve with the codebase, this function typically follows standard configuration path resolution patterns found in similar CLI and agent orchestration tools [1][2][3]. It generally prioritizes the following order to ensure flexible profile isolation and adherence to platform conventions: 1. Environment variable override: It checks for an OPENCODE_CONFIG_DIR environment variable, which allows users to explicitly define a custom configuration directory [4][1][3]. 2. Standard XDG or platform-specific defaults: If the override is not set, it falls back to the standard configuration directory based on the host operating system, such as XDG_CONFIG_HOME/opencode on Linux or corresponding user profile directories on macOS and Windows [1][2]. The function is integral to Orca's ability to manage OpenCode environments, ensuring that configuration, agent settings, and plugin data are correctly located and loaded for the various agents that Orca orchestrates [5][6][7]. Recent updates in the repository have emphasized centralizing and hardening these path resolution strategies to support cross-platform consistency and improve reliability in parallel agent execution [8][9].
Citations:
- 1: https://github.com/alvinunreal/oh-my-opencode-slim/blob/cca59117/src/cli/paths.ts
- 2: https://github.com/sst/opencode/blob/47815645/packages/opencode/src/config/paths.ts
- 3: https://github.com/code-yeongyu/oh-my-openagent/blob/9edaa6e9/src/shared/opencode-config-dir.ts
- 4: https://github.com/allOwO/opencode-codex-orch/blob/19daf2906fffd70d1aff94ba199ab4c8b148a8d5/docs/reference/configuration.md
- 5: https://github.com/stablyai/orca
- 6: https://github.com/stablyai/orca/tree/main
- 7: https://github.com/sst/opencode/blob/9ad6588f/packages/opencode/src/config/config.ts
- 8: fix(opencode): use cross-platform data directory #10362
- 9: Preserve Codex runtime config preferences #3944
🌐 Web query:
site:github.com/stablyai/orca/blob "return existsSync(configDir) ? configDir : undefined"
💡 Result:
The expression return existsSync(configDir)? configDir: undefined is a conditional assignment or return pattern used in Node.js applications to safely resolve a path [1][2]. It performs the following logic: 1. It checks if the path represented by the variable configDir exists on the filesystem using the Node.js built-in fs.existsSync function [1][3]. 2. If the path exists, it returns the value of configDir [1][2]. 3. If the path does not exist, it returns undefined [2]. This pattern is commonly used for validating configuration or directory paths before attempting to use them in downstream operations, such as reading files or initializing application state [1][4][2]. Using undefined as the fallback is a standard way to explicitly represent the absence of a valid path in JavaScript/TypeScript [4][3].
Citations:
- 1: https://github.com/stablyai/orca/blob/main/tests/e2e/helpers/daemon-generation-runtime-fixture.ts
- 2: https://github.com/stablyai/orca/blob/main/tests/e2e/helpers/orca-app.ts
- 3: https://github.com/stablyai/orca/blob/main/mobile/scripts/mobile-expo-cli.mjs
- 4: https://github.com/stablyai/orca/blob/main/src/main/daemon/daemon-host-relocation.ts
🏁 Script executed:
#!/bin/sh
set -eu
base='https://raw.githubusercontent.com/stablyai/orca/main'
for path in \
src/main/opencode/config-source.ts \
src/main/opencode/config-source.test.ts \
src/main/opencode/config-source.spec.ts
do
printf '\n--- %s ---\n' "$path"
curl -fsSL "$base/$path" | sed -n '1,220p' || true
done
printf '\n--- GitHub code search metadata ---\n'
curl -fsSL 'https://api.github.com/repos/stablyai/orca/contents/src/main/opencode' |
jq -r '.[].name' 2>/dev/null || trueRepository: stablyai/orca
Length of output: 1912
Require an existing directory.
existsSync also returns true for a regular file. Return undefined when <configHome>/opencode is not a directory, and add a regression test for an opencode file.
cb32e11 to
089f9e6
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
089f9e6 to
d95cbb1
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: 67d9f9c5-d594-455e-acbd-df83f4716d98
📥 Commits
Reviewing files that changed from the base of the PR and between f088872 and d95cbb1912e80f0bd26785aa429dc2c82d3ae678.
📒 Files selected for processing (52)
src/main/ipc/pty-applied-size-reporting.test.tssrc/main/ipc/pty-buffer-snapshot-dispatch.test.tssrc/main/ipc/pty-codex-account-attribution.test.tssrc/main/ipc/pty-controller-owner-recovery.test.tssrc/main/ipc/pty-controller-ownership-routing.test.tssrc/main/ipc/pty-controller-spawn-admission.test.tssrc/main/ipc/pty-cumulative-ack-accounting.test.tssrc/main/ipc/pty-daemon-controller-teardown.test.tssrc/main/ipc/pty-daemon-spawn-agent-home-env.test.tssrc/main/ipc/pty-daemon-spawn-codex-auth.test.tssrc/main/ipc/pty-daemon-spawn-session-identity.test.tssrc/main/ipc/pty-daemon-spawn-wsl-runtime.test.tssrc/main/ipc/pty-daemon-ssh-lease-lifecycle.test.tssrc/main/ipc/pty-dead-owner-respawn.test.tssrc/main/ipc/pty-delivery-health-heal.test.tssrc/main/ipc/pty-dispatcher-handshake-osc-answers.test.tssrc/main/ipc/pty-global-renderer-credit.test.tssrc/main/ipc/pty-hidden-at-spawn-mark.test.tssrc/main/ipc/pty-ipc-hidden-delivery-gate.test.tssrc/main/ipc/pty-ipc-mock-registry.tssrc/main/ipc/pty-ipc-producer-flow-control.test.tssrc/main/ipc/pty-ipc-suite-environment.tssrc/main/ipc/pty-listener-teardown-and-orphans.test.tssrc/main/ipc/pty-login-shell-startup-commands.test.tssrc/main/ipc/pty-output-batching-drain.test.tssrc/main/ipc/pty-output-drain-rounds.test.tssrc/main/ipc/pty-pane-claim-arbitration.test.tssrc/main/ipc/pty-pane-materialization-race.test.tssrc/main/ipc/pty-pane-reservation-settlement.test.tssrc/main/ipc/pty-pending-output-cap.test.tssrc/main/ipc/pty-persisted-incarnation-repair.test.tssrc/main/ipc/pty-renderer-inflight-credit.test.tssrc/main/ipc/pty-renderer-lifecycle-delivery-reset.test.tssrc/main/ipc/pty-renderer-send-failure-recovery.test.tssrc/main/ipc/pty-restore-record-seeding.test.tssrc/main/ipc/pty-runtime-kill-and-exit.test.tssrc/main/ipc/pty-runtime-ssh-binding-persistence.test.tssrc/main/ipc/pty-serializer-settlement-mapping.test.tssrc/main/ipc/pty-session-liveness-and-ownership.test.tssrc/main/ipc/pty-spawn-cwd-fallback.test.tssrc/main/ipc/pty-spawn-env-agent-overlays.test.tssrc/main/ipc/pty-spawn-env-codex-home-routing.test.tssrc/main/ipc/pty-spawn-env-codex-resume-provenance.test.tssrc/main/ipc/pty-spawn-env-terminal-basics.test.tssrc/main/ipc/pty-spawn-runtime-handle-binding.test.tssrc/main/ipc/pty-startup-barrier-and-listing.test.tssrc/main/ipc/pty-windows-shell-selection.test.tssrc/main/ipc/pty-write-ipc-validation.test.tssrc/main/ipc/pty-wsl-cwd-validation.test.tssrc/main/ipc/pty/host-env/pi-agent.tssrc/main/opencode/config-source.test.tssrc/main/opencode/config-source.ts
🚧 Files skipped from review as they are similar to previous changes (51)
- src/main/ipc/pty-renderer-inflight-credit.test.ts
- src/main/ipc/pty-spawn-runtime-handle-binding.test.ts
- src/main/ipc/pty-serializer-settlement-mapping.test.ts
- src/main/ipc/pty-buffer-snapshot-dispatch.test.ts
- src/main/ipc/pty-pane-reservation-settlement.test.ts
- src/main/ipc/pty-cumulative-ack-accounting.test.ts
- src/main/ipc/pty-restore-record-seeding.test.ts
- src/main/ipc/pty-pending-output-cap.test.ts
- src/main/ipc/pty-login-shell-startup-commands.test.ts
- src/main/ipc/pty-session-liveness-and-ownership.test.ts
- src/main/ipc/pty-spawn-env-terminal-basics.test.ts
- src/main/ipc/pty-output-drain-rounds.test.ts
- src/main/ipc/pty-daemon-spawn-wsl-runtime.test.ts
- src/main/ipc/pty-dead-owner-respawn.test.ts
- src/main/ipc/pty-daemon-controller-teardown.test.ts
- src/main/ipc/pty-runtime-kill-and-exit.test.ts
- src/main/ipc/pty-controller-ownership-routing.test.ts
- src/main/ipc/pty-hidden-at-spawn-mark.test.ts
- src/main/ipc/pty-wsl-cwd-validation.test.ts
- src/main/ipc/pty-runtime-ssh-binding-persistence.test.ts
- src/main/ipc/pty-pane-materialization-race.test.ts
- src/main/ipc/pty-global-renderer-credit.test.ts
- src/main/ipc/pty-applied-size-reporting.test.ts
- src/main/ipc/pty-persisted-incarnation-repair.test.ts
- src/main/ipc/pty-ipc-hidden-delivery-gate.test.ts
- src/main/ipc/pty-write-ipc-validation.test.ts
- src/main/ipc/pty-spawn-env-agent-overlays.test.ts
- src/main/ipc/pty-ipc-suite-environment.ts
- src/main/ipc/pty-ipc-producer-flow-control.test.ts
- src/main/opencode/config-source.ts
- src/main/ipc/pty-listener-teardown-and-orphans.test.ts
- src/main/ipc/pty-dispatcher-handshake-osc-answers.test.ts
- src/main/ipc/pty-renderer-send-failure-recovery.test.ts
- src/main/ipc/pty-pane-claim-arbitration.test.ts
- src/main/ipc/pty-daemon-ssh-lease-lifecycle.test.ts
- src/main/ipc/pty-startup-barrier-and-listing.test.ts
- src/main/ipc/pty-daemon-spawn-agent-home-env.test.ts
- src/main/ipc/pty-spawn-env-codex-home-routing.test.ts
- src/main/ipc/pty-output-batching-drain.test.ts
- src/main/ipc/pty-ipc-mock-registry.ts
- src/main/ipc/pty-controller-spawn-admission.test.ts
- src/main/ipc/pty-delivery-health-heal.test.ts
- src/main/ipc/pty-controller-owner-recovery.test.ts
- src/main/opencode/config-source.test.ts
- src/main/ipc/pty-spawn-env-codex-resume-provenance.test.ts
- src/main/ipc/pty-daemon-spawn-codex-auth.test.ts
- src/main/ipc/pty-spawn-cwd-fallback.test.ts
- src/main/ipc/pty-daemon-spawn-session-identity.test.ts
- src/main/ipc/pty-codex-account-attribution.test.ts
- src/main/ipc/pty-renderer-lifecycle-delivery-reset.test.ts
- src/main/ipc/pty-windows-shell-selection.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
| if (explicitConfigDir) { | ||
| return explicitConfigDir | ||
| } | ||
| return resolveDefaultOpenCodeConfigDir(baseEnv) |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash
set -euo pipefail
rg -n -C 4 'existsSync|statSync|isDirectory|resolveDefaultOpenCodeConfigDir' \
src/main/opencode/config-source.ts
rg -n -C 8 'resolveOpenCodeSourceConfigDir|sourceConfigDir|copy|cp|overlay' \
src/main/ipc/ptyRepository: stablyai/orca
Length of output: 19535
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- repository guidance ---'
find /tmp/coderabbit-repo-knowledge/stablyai/orca-89dc44e4 -maxdepth 2 -type f -name '*.md' -print
printf '%s\n' '--- config resolver ---'
cat -n src/main/opencode/config-source.ts
printf '%s\n' '--- changed resolver and its caller ---'
sed -n '1,18p;186,214p' src/main/ipc/pty/host-env/pi-agent.ts
sed -n '70,92p' src/main/ipc/pty/host-env/assembly.ts
printf '%s\n' '--- overlay consumer definitions ---'
rg -n -C 8 'buildPtyEnv|OPENCODE_CONFIG_DIR|copyFile|cp\(|mkdir|readdir|configDir' src/main/opencode src/main/ipc/pty --glob '*.ts'Repository: stablyai/orca
Length of output: 268
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- repository guidance ---'
find /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4 -maxdepth 2 -type f -name '*.md' -print
printf '%s\n' '--- config resolver ---'
cat -n src/main/opencode/config-source.ts
printf '%s\n' '--- changed resolver and its caller ---'
sed -n '1,18p;186,214p' src/main/ipc/pty/host-env/pi-agent.ts
sed -n '70,92p' src/main/ipc/pty/host-env/assembly.ts
printf '%s\n' '--- overlay consumer definitions ---'
rg -n -C 8 'buildPtyEnv|OPENCODE_CONFIG_DIR|copyFile|cp\(|mkdir|readdir|configDir' src/main/opencode src/main/ipc/pty --glob '*.ts'Repository: stablyai/orca
Length of output: 50369
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- applicable conventions and learnings ---'
cat /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions/repo-wide.md
printf '%s\n' '--- PTY learnings ---'
cat /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings/src-main-pty.md
printf '%s\n' '--- exact overlay flow ---'
sed -n '68,106p;108,120p;155,172p;205,221p' src/main/opencode/hook-service.ts
printf '%s\n' '--- resolver tests, including missing-path behavior ---'
sed -n '1,90p' src/main/opencode/config-source.test.ts
printf '%s\n' '--- documented OPENCODE_CONFIG_DIR contract ---'
cat docs/opencode-config-dir-collision.mdRepository: stablyai/orca
Length of output: 8267
🌐 Web query:
OpenCode OPENCODE_CONFIG_DIR environment variable directory configuration documentation
💡 Result:
In OpenCode, the OPENCODE_CONFIG_DIR environment variable is used to specify a custom directory for configuration [1][2][3]. When set, OpenCode searches this custom directory for agents, commands, modes, and plugins, using the same structure as the default.opencode directory [1][3]. Because this custom directory is loaded after the global configuration and the standard.opencode directory, any settings defined within it can override those from the default locations [1][2][3]. You can set this variable in your terminal before running OpenCode commands [1][3]: export OPENCODE_CONFIG_DIR=/path/to/my/config-directory opencode run "Hello world" OpenCode is an open-source AI coding agent developed by Anomaly that assists with software development tasks via terminal, desktop, or IDE interfaces [4][5]. The implementation of this configuration logic is managed within the OpenCode codebase, where the value is retrieved dynamically at runtime [6].
Citations:
- 1: https://dev.opencode.ai/docs/config/
- 2: https://github.com/anomalyco/opencode/blob/ec3ae17e/packages/web/src/content/docs/config.mdx
- 3: https://anomalyco-opencode.mintlify.app/config
- 4: https://en.wikipedia.org/wiki/OpenCode
- 5: https://www.tecmint.com/opencode-ai-coding-agent-linux/
- 6: https://github.com/anomalyco/opencode/blob/46f243fe/packages/opencode/src/flag/flag.ts
Require the fallback path to be a directory.
existsSync(configDir) also accepts regular files. If ~/.config/opencode is a file, the overlay flow can return it as OPENCODE_CONFIG_DIR, although OpenCode expects a configuration directory. Use a directory check or add a regression test.
Source: Linters/SAST tools
d95cbb1 to
0cc003b
Compare
ac8bd76 to
7e1d7cb
Compare
Resolve the default config source from each PTY environment, including static shell exports, before creating the existing source-scoped overlay. This preserves user models, plugins, and auth while keeping the Orca status plugin installed. Fixes stablyai#9186. Co-authored-by: Brennan Benson <79079362+brennanb2025@users.noreply.github.com>
7e1d7cb to
e0b85d2
Compare
|
PR #25296 is merged and credits @inaemin for this proposal. It fixes Orca putting OpenCode hooks in the wrong config directory when a terminal uses a different HOME, XDG_CONFIG_HOME, or shell. Validation with installed OpenCode 2.0.16 found the hook active in all five tested launch cases. This PR remains open for its broader default model and OhMyOpenCode support; those are still outstanding. |
|
Thanks @inaemin for the detailed write-up and the fix! This is already fixed on main by #21854 (438744c). When |
Summary
When a user launches OpenCode in Orca without explicitly setting
OPENCODE_CONFIG_DIR, Orca handed OpenCode a bareshared/directory that contained only Orca's status plugin. The user's default OpenCode config at~/.config/opencode/(opencode.json,oh-my-openagent.json, auth, plugins) was never mirrored, so it was invisible to the OpenCode process.Concretely,
oh-my-openagentagents such assisyphusstill appeared by name (their definitions load from the un-redirected package cache~/.cache/opencode/packages/), but their per-agent model mapping — which lives in~/.config/opencode/oh-my-openagent.json— was dropped, so they silently ran underclaude-opus-4-7instead of the configuredopencode-go/*model.This PR makes
OpenCodeHookService.buildPtyEnv()detect the default OpenCode config directory via the same XDG fallback OpenCode/OMO use (XDG_CONFIG_HOME/opencode→~/.config/opencode) and mirror it into the source-scoped overlay alongside Orca's status plugin, exactly as it already does when the user setsOPENCODE_CONFIG_DIRexplicitly. When no default dir exists, behavior is unchanged (bare shared plugin dir).Fixes #9186.
Screenshots
No visual change. This is a main-process env/overlay fix with no renderer surface.
Testing
pnpm lint(oxlint clean on changed files)pnpm typecheckpnpm test(src/main/opencode/hook-service.test.ts— 29/29 passing)pnpm buildAdded a regression test asserting that, with no explicit
OPENCODE_CONFIG_DIR,buildPtyEnvmirrors the default XDG config dir into an overlay that contains both the user'sopencode.jsonand Orca'splugins/orca-opencode-status.js— not the bareshared/dir. Existing tests were isolated by pointingXDG_CONFIG_HOMEat an empty temp dir inbeforeAll, so a real~/.config/opencodeon the dev machine can no longer leak in and flip them onto the overlay path.Also verified end-to-end on a clean build: without the change the agent runs under
claude-opus-4-7; with it, the agent runs under the configuredopencode-go/*model.AI Review Report
Reviewed with the AI coding agent for:
getDefaultOpenCodeConfigDir()usespath.join+os.homedir()(no hardcoded separators) and readsXDG_CONFIG_HOME. It only detects and returns a source dir; the actual mirroring reuses the existingmirrorUserConfig/overlay-mirrorpath that already handles Windows junctions vs POSIX symlinks. No new shortcut, label, or shell behavior was introduced.OpenCodeHookService, invoked only on the host-local PTY path (buildPtyHostEnv), which callers already skip for SSH connections. No assumption of local-only execution was added.existsSync(configDir), so users without a default OpenCode config keep the previous bare-shared behavior. The explicit-OPENCODE_CONFIG_DIRpath is untouched. A typo'd/non-existent source dir is still passed through verbatim (nomkdir -pof the user's path), preserving the collision-avoidance behavior indocs/opencode-config-dir-collision.md.existsSyncper PTY spawn on the fallback path; negligible and off the hot path.Security Audit
XDG_CONFIG_HOME) /homedir(), joined withpath.join. It is never used to build a shell command; it feeds the existing symlink/junction mirror, which already refuses to operate outside the overlay root during teardown (overlay-mirror.ts, issue [Bug]: work with Pi #1083 hardening).plugins/dir, andwritePluginIntoOverlayunlinks before write so a mirrored symlink can never be followed back into the user's real files.Notes
OPENCODE_CONFIG_DIRis unset and a default~/.config/opencode(or$XDG_CONFIG_HOME/opencode) exists. No behavior change when the var is set explicitly or when no default dir exists.oh-my-opencode@3.15.2in the package cache; that was verified to be a red herring (cache held the current 4.18.2). The real cause is the missing default-config detection fixed here.X (Twitter): @inaemin
ELI5
OpenCode launched from Orca without OPENCODE_CONFIG_DIR only saw a tiny shared plugin folder, not your real ~/.config/opencode setup. Default config is mirrored so plugins and auth work as outside Orca.