@@ -16,6 +16,7 @@ import { TuiConfig } from "@/cli/cmd/tui/config/tui"
1616import { Log } from "@/util"
1717import { errorData , errorMessage } from "@/util/error"
1818import { isRecord } from "@/util/record"
19+ import { Instance } from "@/project/instance"
1920import {
2021 readPackageThemes ,
2122 readPluginId ,
@@ -789,7 +790,13 @@ async function addPluginBySpec(state: RuntimeState | undefined, raw: string) {
789790 state . pending . delete ( spec )
790791 return true
791792 }
792- const ready = await resolveExternalPlugins ( [ cfg ] , ( ) => TuiConfig . waitForDependencies ( ) )
793+ const ready = await Instance . provide ( {
794+ directory : state . directory ,
795+ fn : ( ) => resolveExternalPlugins ( [ cfg ] , ( ) => TuiConfig . waitForDependencies ( ) ) ,
796+ } ) . catch ( ( error ) => {
797+ fail ( "failed to add tui plugin" , { path : next , error } )
798+ return [ ] as PluginLoad [ ]
799+ } )
793800 if ( ! ready . length ) {
794801 return false
795802 }
@@ -980,37 +987,42 @@ export namespace TuiPluginRuntime {
980987 }
981988 runtime = next
982989 try {
983- const records = Flag . OPENCODE_PURE ? [ ] : ( config . plugin_origins ?? [ ] )
984- if ( Flag . OPENCODE_PURE && config . plugin_origins ?. length ) {
985- log . info ( "skipping external tui plugins in pure mode" , { count : config . plugin_origins . length } )
986- }
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+ }
987997
988- for ( const item of INTERNAL_TUI_PLUGINS ) {
989- log . info ( "loading internal tui plugin" , { id : item . id } )
990- const entry = loadInternalPlugin ( item )
991- const meta = createMeta ( entry . source , entry . spec , entry . target , undefined , entry . id )
992- addPluginEntry ( next , {
993- id : entry . id ,
994- load : entry ,
995- meta,
996- themes : { } ,
997- plugin : entry . module . tui ,
998- enabled : true ,
999- } )
1000- }
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+ }
10011011
1002- const ready = await resolveExternalPlugins ( records , ( ) => TuiConfig . waitForDependencies ( ) )
1003- await addExternalPluginEntries ( next , ready )
1004-
1005- applyInitialPluginEnabledState ( next , config )
1006- for ( const plugin of next . plugins ) {
1007- if ( ! plugin . enabled ) continue
1008- // Keep plugin execution sequential for deterministic side effects:
1009- // command registration order affects keybind/command precedence,
1010- // route registration is last-wins when ids collide,
1011- // and hook chains rely on stable plugin ordering.
1012- await activatePluginEntry ( next , plugin , false )
1013- }
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+ } )
10141026 } catch ( error ) {
10151027 fail ( "failed to load tui plugins" , { directory : cwd , error } )
10161028 }
0 commit comments