@@ -918,113 +918,113 @@ async function installPluginBySpec(
918918 }
919919}
920920
921- export namespace TuiPluginRuntime {
922- let dir = ""
923- let loaded : Promise < void > | undefined
924- let runtime : RuntimeState | undefined
925- export const Slot = View
926-
927- export async function init ( input : { api : HostPluginApi ; config : TuiConfig . Info } ) {
928- const cwd = process . cwd ( )
929- if ( loaded ) {
930- if ( dir !== cwd ) {
931- throw new Error ( `TuiPluginRuntime.init() called with a different working directory. expected=${ dir } got=${ cwd } ` )
932- }
933- return loaded
921+ let dir = ""
922+ let loaded : Promise < void > | undefined
923+ let runtime : RuntimeState | undefined
924+ export const Slot = View
925+
926+ export async function init ( input : { api : HostPluginApi ; config : TuiConfig . Info } ) {
927+ const cwd = process . cwd ( )
928+ if ( loaded ) {
929+ if ( dir !== cwd ) {
930+ throw new Error ( `TuiPluginRuntime.init() called with a different working directory. expected=${ dir } got=${ cwd } ` )
934931 }
935-
936- dir = cwd
937- loaded = load ( input )
938932 return loaded
939933 }
940934
941- export function list ( ) {
942- if ( ! runtime ) return [ ]
943- return listPluginStatus ( runtime )
944- }
935+ dir = cwd
936+ loaded = load ( input )
937+ return loaded
938+ }
945939
946- export async function activatePlugin ( id : string ) {
947- return activatePluginById ( runtime , id , true )
948- }
940+ export function list ( ) {
941+ if ( ! runtime ) return [ ]
942+ return listPluginStatus ( runtime )
943+ }
949944
950- export async function deactivatePlugin ( id : string ) {
951- return deactivatePluginById ( runtime , id , true )
952- }
945+ export async function activatePlugin ( id : string ) {
946+ return activatePluginById ( runtime , id , true )
947+ }
953948
954- export async function addPlugin ( spec : string ) {
955- return addPluginBySpec ( runtime , spec )
956- }
949+ export async function deactivatePlugin ( id : string ) {
950+ return deactivatePluginById ( runtime , id , true )
951+ }
957952
958- export async function installPlugin ( spec : string , options ?: { global ?: boolean } ) {
959- return installPluginBySpec ( runtime , spec , options ?. global )
960- }
953+ export async function addPlugin ( spec : string ) {
954+ return addPluginBySpec ( runtime , spec )
955+ }
961956
962- export async function dispose ( ) {
963- const task = loaded
964- loaded = undefined
965- dir = ""
966- if ( task ) await task
967- const state = runtime
968- runtime = undefined
969- if ( ! state ) return
970- const queue = [ ...state . plugins ] . reverse ( )
971- for ( const plugin of queue ) {
972- await deactivatePluginEntry ( state , plugin , false )
973- }
957+ export async function installPlugin ( spec : string , options ?: { global ?: boolean } ) {
958+ return installPluginBySpec ( runtime , spec , options ?. global )
959+ }
960+
961+ export async function dispose ( ) {
962+ const task = loaded
963+ loaded = undefined
964+ dir = ""
965+ if ( task ) await task
966+ const state = runtime
967+ runtime = undefined
968+ if ( ! state ) return
969+ const queue = [ ...state . plugins ] . reverse ( )
970+ for ( const plugin of queue ) {
971+ await deactivatePluginEntry ( state , plugin , false )
974972 }
973+ }
975974
976- async function load ( input : { api : Api ; config : TuiConfig . Info } ) {
977- const { api, config } = input
978- const cwd = process . cwd ( )
979- const slots = setupSlots ( api )
980- const next : RuntimeState = {
975+ async function load ( input : { api : Api ; config : TuiConfig . Info } ) {
976+ const { api, config } = input
977+ const cwd = process . cwd ( )
978+ const slots = setupSlots ( api )
979+ const next : RuntimeState = {
980+ directory : cwd ,
981+ api,
982+ slots,
983+ plugins : [ ] ,
984+ plugins_by_id : new Map ( ) ,
985+ pending : new Map ( ) ,
986+ }
987+ runtime = next
988+ try {
989+ await Instance . provide ( {
981990 directory : cwd ,
982- api,
983- slots,
984- plugins : [ ] ,
985- plugins_by_id : new Map ( ) ,
986- pending : new Map ( ) ,
987- }
988- runtime = next
989- try {
990- await Instance . provide ( {
991- directory : cwd ,
992- fn : async ( ) => {
993- const records = Flag . OPENCODE_PURE ? [ ] : ( config . plugin_origins ?? [ ] )
994- if ( Flag . OPENCODE_PURE && config . plugin_origins ?. length ) {
995- log . info ( "skipping external tui plugins in pure mode" , { count : config . plugin_origins . length } )
996- }
991+ fn : async ( ) => {
992+ const records = Flag . OPENCODE_PURE ? [ ] : ( config . plugin_origins ?? [ ] )
993+ if ( Flag . OPENCODE_PURE && config . plugin_origins ?. length ) {
994+ log . info ( "skipping external tui plugins in pure mode" , { count : config . plugin_origins . length } )
995+ }
997996
998- for ( const item of INTERNAL_TUI_PLUGINS ) {
999- log . info ( "loading internal tui plugin" , { id : item . id } )
1000- const entry = loadInternalPlugin ( item )
1001- const meta = createMeta ( entry . source , entry . spec , entry . target , undefined , entry . id )
1002- addPluginEntry ( next , {
1003- id : entry . id ,
1004- load : entry ,
1005- meta,
1006- themes : { } ,
1007- plugin : entry . module . tui ,
1008- enabled : true ,
1009- } )
1010- }
997+ for ( const item of INTERNAL_TUI_PLUGINS ) {
998+ log . info ( "loading internal tui plugin" , { id : item . id } )
999+ const entry = loadInternalPlugin ( item )
1000+ const meta = createMeta ( entry . source , entry . spec , entry . target , undefined , entry . id )
1001+ addPluginEntry ( next , {
1002+ id : entry . id ,
1003+ load : entry ,
1004+ meta,
1005+ themes : { } ,
1006+ plugin : entry . module . tui ,
1007+ enabled : true ,
1008+ } )
1009+ }
10111010
1012- const ready = await resolveExternalPlugins ( records , ( ) => TuiConfig . waitForDependencies ( ) )
1013- await addExternalPluginEntries ( next , ready )
1014-
1015- applyInitialPluginEnabledState ( next , config )
1016- for ( const plugin of next . plugins ) {
1017- if ( ! plugin . enabled ) continue
1018- // Keep plugin execution sequential for deterministic side effects:
1019- // command registration order affects keybind/command precedence,
1020- // route registration is last-wins when ids collide,
1021- // and hook chains rely on stable plugin ordering.
1022- await activatePluginEntry ( next , plugin , false )
1023- }
1024- } ,
1025- } )
1026- } catch ( error ) {
1027- fail ( "failed to load tui plugins" , { directory : cwd , error } )
1028- }
1011+ const ready = await resolveExternalPlugins ( records , ( ) => TuiConfig . waitForDependencies ( ) )
1012+ await addExternalPluginEntries ( next , ready )
1013+
1014+ applyInitialPluginEnabledState ( next , config )
1015+ for ( const plugin of next . plugins ) {
1016+ if ( ! plugin . enabled ) continue
1017+ // Keep plugin execution sequential for deterministic side effects:
1018+ // command registration order affects keybind/command precedence,
1019+ // route registration is last-wins when ids collide,
1020+ // and hook chains rely on stable plugin ordering.
1021+ await activatePluginEntry ( next , plugin , false )
1022+ }
1023+ } ,
1024+ } )
1025+ } catch ( error ) {
1026+ fail ( "failed to load tui plugins" , { directory : cwd , error } )
10291027 }
10301028}
1029+
1030+ export * as TuiPluginRuntime from "./runtime"
0 commit comments