@@ -22,13 +22,14 @@ import { ConfigMarkdown } from "./markdown"
2222export namespace Config {
2323 const log = Log . create ( { service : "config" } )
2424
25- // Custom merge function that concatenates plugin arrays instead of replacing them
26- function mergeConfigWithPlugins ( target : Info , source : Info ) : Info {
25+ // Custom merge function that concatenates array fields instead of replacing them
26+ function mergeConfigConcatArrays ( target : Info , source : Info ) : Info {
2727 const merged = mergeDeep ( target , source )
28- // If both configs have plugin arrays, concatenate them instead of replacing
2928 if ( target . plugin && source . plugin ) {
30- const pluginSet = new Set ( [ ...target . plugin , ...source . plugin ] )
31- merged . plugin = Array . from ( pluginSet )
29+ merged . plugin = Array . from ( new Set ( [ ...target . plugin , ...source . plugin ] ) )
30+ }
31+ if ( target . instructions && source . instructions ) {
32+ merged . instructions = Array . from ( new Set ( [ ...target . instructions , ...source . instructions ] ) )
3233 }
3334 return merged
3435 }
@@ -39,27 +40,27 @@ export namespace Config {
3940
4041 // Override with custom config if provided
4142 if ( Flag . OPENCODE_CONFIG ) {
42- result = mergeConfigWithPlugins ( result , await loadFile ( Flag . OPENCODE_CONFIG ) )
43+ result = mergeConfigConcatArrays ( result , await loadFile ( Flag . OPENCODE_CONFIG ) )
4344 log . debug ( "loaded custom config" , { path : Flag . OPENCODE_CONFIG } )
4445 }
4546
4647 for ( const file of [ "opencode.jsonc" , "opencode.json" ] ) {
4748 const found = await Filesystem . findUp ( file , Instance . directory , Instance . worktree )
4849 for ( const resolved of found . toReversed ( ) ) {
49- result = mergeConfigWithPlugins ( result , await loadFile ( resolved ) )
50+ result = mergeConfigConcatArrays ( result , await loadFile ( resolved ) )
5051 }
5152 }
5253
5354 if ( Flag . OPENCODE_CONFIG_CONTENT ) {
54- result = mergeConfigWithPlugins ( result , JSON . parse ( Flag . OPENCODE_CONFIG_CONTENT ) )
55+ result = mergeConfigConcatArrays ( result , JSON . parse ( Flag . OPENCODE_CONFIG_CONTENT ) )
5556 log . debug ( "loaded custom config from OPENCODE_CONFIG_CONTENT" )
5657 }
5758
5859 for ( const [ key , value ] of Object . entries ( auth ) ) {
5960 if ( value . type === "wellknown" ) {
6061 process . env [ value . key ] = value . token
6162 const wellknown = ( await fetch ( `${ key } /.well-known/opencode` ) . then ( ( x ) => x . json ( ) ) ) as any
62- result = mergeConfigWithPlugins ( result , await load ( JSON . stringify ( wellknown . config ?? { } ) , process . cwd ( ) ) )
63+ result = mergeConfigConcatArrays ( result , await load ( JSON . stringify ( wellknown . config ?? { } ) , process . cwd ( ) ) )
6364 }
6465 }
6566
@@ -94,7 +95,7 @@ export namespace Config {
9495 if ( dir . endsWith ( ".opencode" ) || dir === Flag . OPENCODE_CONFIG_DIR ) {
9596 for ( const file of [ "opencode.jsonc" , "opencode.json" ] ) {
9697 log . debug ( `loading config from ${ path . join ( dir , file ) } ` )
97- result = mergeConfigWithPlugins ( result , await loadFile ( path . join ( dir , file ) ) )
98+ result = mergeConfigConcatArrays ( result , await loadFile ( path . join ( dir , file ) ) )
9899 // to satisfy the type checker
99100 result . agent ??= { }
100101 result . mode ??= { }
0 commit comments