11import type { Plugin } from "@opencode-ai/plugin" ;
22import { existsSync , readFileSync } from "fs" ;
33import * as path from "path" ;
4+ import * as os from "os" ;
45
56import { parseConfig } from "./config/schema.js" ;
67import { 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