-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(install): respect OPENCODE_CONFIG_DIR env var for global config path #573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
c4a8a9d
eab704e
411c420
c1475a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,7 +96,7 @@ export default defineCommand({ | |
|
|
||
| try { | ||
| const plugin = await loadClaudePlugin(resolvedPlugin.path) | ||
| const outputRoot = resolveOutputRoot(args.output) | ||
| const { root: outputRoot, isGlobalOpenCodeConfig } = resolveOutputRoot(args.output) | ||
| const codexHome = resolveTargetHome(args.codexHome, path.join(os.homedir(), ".codex")) | ||
| const piHome = resolveTargetHome(args.piHome, path.join(os.homedir(), ".pi", "agent")) | ||
| const hasExplicitOutput = Boolean(args.output && String(args.output).trim()) | ||
|
|
@@ -144,7 +144,9 @@ export default defineCommand({ | |
| pluginName: plugin.manifest.name, | ||
| hasExplicitOutput, | ||
| }) | ||
| await handler.write(root, bundle) | ||
| const writeScope = | ||
| tool.name === "opencode" && isGlobalOpenCodeConfig ? "global" : handler.defaultScope | ||
| await handler.write(root, bundle, writeScope) | ||
| console.log(`Installed ${plugin.manifest.name} to ${tool.name} at ${root}`) | ||
| } | ||
|
|
||
|
|
@@ -163,6 +165,12 @@ export default defineCommand({ | |
| } | ||
|
|
||
| const resolvedScope = validateScope(targetName, target, args.scope ? String(args.scope) : undefined) | ||
| // For OpenCode, if the output root is the global config dir (default or OPENCODE_CONFIG_DIR), | ||
| // use "global" scope so writeOpenCodeBundle writes the flat layout regardless of basename. | ||
| const effectiveScope = | ||
| targetName === "opencode" && isGlobalOpenCodeConfig && resolvedScope === undefined | ||
| ? "global" | ||
| : resolvedScope | ||
|
|
||
| const bundle = target.convert(plugin, options) | ||
| if (!bundle) { | ||
|
|
@@ -177,9 +185,9 @@ export default defineCommand({ | |
| qwenHome, | ||
| pluginName: plugin.manifest.name, | ||
| hasExplicitOutput, | ||
| scope: resolvedScope, | ||
| scope: effectiveScope, | ||
| }) | ||
| await target.write(primaryOutputRoot, bundle, resolvedScope) | ||
| await target.write(primaryOutputRoot, bundle, effectiveScope) | ||
| console.log(`Installed ${plugin.manifest.name} to ${primaryOutputRoot}`) | ||
|
|
||
| const extraTargets = parseExtraTargets(args.also) | ||
|
|
@@ -259,14 +267,19 @@ function parseExtraTargets(value: unknown): string[] { | |
| .filter(Boolean) | ||
| } | ||
|
|
||
| function resolveOutputRoot(value: unknown): string { | ||
| function resolveOutputRoot(value: unknown): { root: string; isGlobalOpenCodeConfig: boolean } { | ||
| if (value && String(value).trim()) { | ||
| const expanded = expandHome(String(value).trim()) | ||
| return path.resolve(expanded) | ||
| return { root: path.resolve(expanded), isGlobalOpenCodeConfig: false } | ||
| } | ||
| // OpenCode global config lives at ~/.config/opencode per XDG spec | ||
| // OpenCode global config: respect OPENCODE_CONFIG_DIR if set, otherwise | ||
| // fall back to ~/.config/opencode per XDG spec. | ||
| // See: https://opencode.ai/docs/config/ | ||
| return path.join(os.homedir(), ".config", "opencode") | ||
| const envDir = process.env.OPENCODE_CONFIG_DIR?.trim() | ||
| if (envDir) { | ||
| return { root: path.resolve(expandHome(envDir)), isGlobalOpenCodeConfig: true } | ||
|
Comment on lines
+278
to
+280
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. |
||
| } | ||
|
Comment on lines
+278
to
+281
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Returning Useful? React with 👍 / 👎. |
||
| return { root: path.join(os.homedir(), ".config", "opencode"), isGlobalOpenCodeConfig: true } | ||
| } | ||
|
|
||
| async function resolveBundledPluginPath(pluginName: string): Promise<string | null> { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import os from "os" | ||
| import path from "path" | ||
| import type { ClaudeHomeConfig } from "../parsers/claude-home" | ||
| import { expandHome } from "../utils/resolve-home" | ||
| import { syncToCodex } from "./codex" | ||
| import { syncToCopilot } from "./copilot" | ||
| import { syncToDroid } from "./droid" | ||
|
|
@@ -12,6 +13,14 @@ import { syncToPi } from "./pi" | |
| import { syncToQwen } from "./qwen" | ||
| import { syncToWindsurf } from "./windsurf" | ||
|
|
||
| function resolveOpenCodeConfigDir(home: string): string { | ||
| const envDir = process.env.OPENCODE_CONFIG_DIR?.trim() | ||
| if (envDir) { | ||
| return path.resolve(expandHome(envDir)) | ||
| } | ||
| return path.join(home, ".config", "opencode") | ||
| } | ||
|
|
||
| function getCopilotHomeRoot(home: string): string { | ||
| return path.join(home, ".copilot") | ||
| } | ||
|
|
@@ -43,10 +52,10 @@ export const syncTargets: SyncTargetDefinition[] = [ | |
| { | ||
| name: "opencode", | ||
| detectPaths: (home, cwd) => [ | ||
| path.join(home, ".config", "opencode"), | ||
| resolveOpenCodeConfigDir(home), | ||
| path.join(cwd, ".opencode"), | ||
|
Comment on lines
54
to
56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
With this change, OpenCode detection uses Useful? React with 👍 / 👎. |
||
| ], | ||
| resolveOutputRoot: (home) => path.join(home, ".config", "opencode"), | ||
| resolveOutputRoot: (home) => resolveOpenCodeConfigDir(home), | ||
| sync: syncToOpenCode, | ||
|
Comment on lines
52
to
59
|
||
| }, | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--to allpathFresh evidence from this commit:
isGlobalOpenCodeConfigandeffectiveScopewere added, buteffectiveScopeis only computed in the single-target branch after thetargetName === "all"early return. IfOPENCODE_CONFIG_DIRis set to a directory whose basename is notopencode/.opencode,install --to allstill callswriteOpenCodeBundlewithoutglobalscope, so OpenCode files are written under<envDir>/.opencode/...instead of the global<envDir>/{agents,skills,commands}layout.Useful? React with 👍 / 👎.