Skip to content

Commit 3d15bb1

Browse files
committed
refactor: use ~/.config/opencode instead of npm global prefix for plugin discovery
- Remove npm global prefix lookup (execSync npm config get prefix) - Add user config directory: ~/.config/opencode/node_modules/ - Plugin discovery now searches: user config -> local (last wins) - Remove unused execSync import
1 parent 5890bb6 commit 3d15bb1

2 files changed

Lines changed: 15 additions & 23 deletions

File tree

AGENTS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ console.log(`${colors.green} + ${message}${colors.reset}`);
160160
### Plugin Discovery (lib/discovery.js)
161161
162162
Plugins are discovered from two locations:
163-
1. **Global**: `npm config get prefix`/lib/node_modules/
163+
1. **User config**: `~/.config/opencode/node_modules/`
164164
2. **Local**: `{targetDir}/node_modules/`
165165
166-
Priority: **last wins** (local overrides global)
166+
Priority: **last wins** (local overrides user)
167167
168168
### Plugin Types
169169

lib/discovery.js

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Plugin Discovery Module
33
*
44
* Discovers OpenCode plugins from two locations (priority: last wins):
5-
* 1. Global: npm global prefix (npm install -g)
5+
* 1. User config: ~/.config/opencode/node_modules/
66
* 2. Local: {targetDir}/node_modules/
77
*
88
* Each location can contain two types of packages:
@@ -13,52 +13,44 @@
1313
import fs from 'fs';
1414
import os from 'os';
1515
import path from 'path';
16-
import { execSync } from 'child_process';
1716

1817
/**
19-
* Gets the npm global prefix directory.
20-
* This is where `npm install -g` installs packages.
18+
* Gets the user config directory for OpenCode plugins.
19+
* This is where user-level plugins are installed.
2120
*
22-
* @returns {string|null} Path to npm global prefix or null if not determinable
21+
* @returns {string} Path to ~/.config/opencode/node_modules
2322
*/
24-
function getGlobalDir() {
25-
try {
26-
const prefix = execSync('npm config get prefix', { encoding: 'utf-8' }).trim();
27-
return path.join(prefix, 'lib', 'node_modules');
28-
} catch {
29-
return null;
30-
}
23+
function getUserConfigDir() {
24+
return path.join(os.homedir(), '.config', 'opencode', 'node_modules');
3125
}
3226

3327
/**
3428
* Discovers all available plugins from all locations.
3529
*
3630
* Priority (last wins):
37-
* 1. Global: npm global prefix (npm install -g)
31+
* 1. User config: ~/.config/opencode/node_modules/
3832
* 2. Local: {targetDir}/node_modules/
3933
*
4034
* @param {string} targetDir - The .opencode directory (e.g., /project/.opencode)
4135
* @returns {Map<string, PluginDescriptor>} Map of plugin name to descriptor
4236
*/
4337
export function discoverPlugins(targetDir) {
44-
const globalDir = getGlobalDir();
38+
const userConfigDir = getUserConfigDir();
4539

4640
// Scan all locations (order matters: last wins)
4741
const allPlugins = new Map();
4842

49-
// 1. Global (lowest priority)
50-
if (globalDir) {
51-
const globalPlugins = scanLocation(globalDir, 'global');
52-
for (const [name, descriptor] of globalPlugins.entries()) {
53-
allPlugins.set(name, descriptor);
54-
}
43+
// 1. User config (lower priority)
44+
const userPlugins = scanLocation(userConfigDir, 'user');
45+
for (const [name, descriptor] of userPlugins.entries()) {
46+
allPlugins.set(name, descriptor);
5547
}
5648

5749
// 2. Local (highest priority)
5850
const localPlugins = scanLocation(path.join(targetDir, 'node_modules'), 'local');
5951
for (const [name, descriptor] of localPlugins.entries()) {
6052
if (allPlugins.has(name)) {
61-
console.log(` ⚠️ Plugin "${name}" found in local, overrides global`);
53+
console.log(` ⚠️ Plugin "${name}" found in local, overrides user`);
6254
}
6355
allPlugins.set(name, descriptor);
6456
}

0 commit comments

Comments
 (0)