Skip to content

Commit cd85924

Browse files
committed
feat: support global config file (~/.config/opencode/codebase-index.json)
1 parent 5eea67c commit cd85924

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "opencode-codebase-index",
3-
"version": "0.2.2",
3+
"version": "0.2.3",
44
"description": "Semantic codebase indexing and search for OpenCode - find code by meaning, not just keywords",
55
"type": "module",
66
"main": "dist/index.js",

src/index.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Plugin } from "@opencode-ai/plugin";
22
import { existsSync, readFileSync } from "fs";
33
import * as path from "path";
4+
import * as os from "os";
45

56
import { parseConfig } from "./config/schema.js";
67
import { Indexer } from "./indexer/index.js";
@@ -13,16 +14,28 @@ import {
1314
initializeTools,
1415
} from "./tools/index.js";
1516

16-
function loadPluginConfig(projectRoot: string): unknown {
17-
const configPath = path.join(projectRoot, ".opencode", "codebase-index.json");
17+
function loadJsonFile(filePath: string): unknown {
1818
try {
19-
if (existsSync(configPath)) {
20-
const content = readFileSync(configPath, "utf-8");
19+
if (existsSync(filePath)) {
20+
const content = readFileSync(filePath, "utf-8");
2121
return JSON.parse(content);
2222
}
23-
} catch {
24-
// Ignore config file read errors, use defaults
23+
} catch { /* ignore */ }
24+
return null;
25+
}
26+
27+
function loadPluginConfig(projectRoot: string): unknown {
28+
const projectConfig = loadJsonFile(path.join(projectRoot, ".opencode", "codebase-index.json"));
29+
if (projectConfig) {
30+
return projectConfig;
2531
}
32+
33+
const globalConfigPath = path.join(os.homedir(), ".config", "opencode", "codebase-index.json");
34+
const globalConfig = loadJsonFile(globalConfigPath);
35+
if (globalConfig) {
36+
return globalConfig;
37+
}
38+
2639
return {};
2740
}
2841

0 commit comments

Comments
 (0)