11export * as CustomContextPlugin from "./context.js"
22
3- import { relative } from "path"
3+ import { join , relative } from "path"
44import { define } from "@opencode/plugin/effect/plugin"
55import { CustomContext } from "@opencode/schema/custom-context"
66import { FSUtil } from "@opencode/util/fs-util"
7+ import { Global } from "@opencode/util/global"
78import { Effect , Option , Schema } from "effect"
89import { InstructionDiscovery } from "../../instruction-discovery.js"
910import { Instructions } from "../../instructions/index.js"
@@ -16,15 +17,19 @@ export const Plugin = define({
1617 id : "custom.context" ,
1718 effect : Effect . fn ( "CustomContextPlugin" ) ( function * ( ctx ) {
1819 const discovery = yield * InstructionDiscovery . Service
20+ const fs = yield * FSUtil . Service
1921 const location = yield * Location . Service
22+ const global = yield * Global . Service
23+ const config = global . config
24+ const configReal = yield * fs . resolve ( config )
2025
2126 yield * ctx . rpc
2227 . register ( CustomContext . Contract , {
2328 list : ( input ) =>
2429 Effect . gen ( function * ( ) {
2530 const loaded = yield * discovery . list ( )
2631 const history = yield * ctx . session . context ( { sessionID : input . sessionID } )
27- return contextFiles ( location . project . directory , loaded , history )
32+ return contextFiles ( location . project . directory , global . home , config , configReal , loaded , history )
2833 } ) . pipe ( Effect . orDie ) ,
2934 } )
3035 . pipe ( Effect . orDie )
@@ -37,6 +42,9 @@ const InjectedPaths = Schema.Struct({
3742
3843export function contextFiles (
3944 root : string ,
45+ home : string ,
46+ config : string ,
47+ configReal : string ,
4048 loaded : ReadonlyArray < InstructionDiscovery . File > | Instructions . Unavailable ,
4149 history : ReadonlyArray < SessionMessage . Info > ,
4250) {
@@ -47,6 +55,16 @@ export function contextFiles(
4755 const ambient = Array . isArray ( loaded ) ? loaded . map ( ( file ) => file . path ) : [ ]
4856 return {
4957 unavailable : ! Array . isArray ( loaded ) ,
50- files : [ ...new Set ( [ ...ambient , ...nested ] ) ] . map ( ( file ) => ( FSUtil . contains ( root , file ) ? relative ( root , file ) : file ) ) ,
58+ files : [ ...new Set ( [ ...ambient , ...nested ] ) ] . map ( ( file ) => display ( root , home , config , configReal , file ) ) ,
5159 }
5260}
61+
62+ // Discovery stores real paths, so a config dir that is a symlink shows its target.
63+ // Display the path the user configured instead.
64+ function display ( root : string , home : string , config : string , configReal : string , file : string ) {
65+ if ( FSUtil . contains ( root , file ) ) return relative ( root , file )
66+ const logical = FSUtil . contains ( configReal , file ) ? join ( config , relative ( configReal , file ) ) : file
67+ if ( ! FSUtil . contains ( home , logical ) ) return logical
68+ const rest = relative ( home , logical )
69+ return rest === "" ? "~" : `~/${ rest } `
70+ }
0 commit comments