1- import { resolveAgentWorkspaceDir , resolveDefaultAgentId } from "../agents/agent-scope.js" ;
21import { collectUniqueCommandDescriptors } from "../cli/program/command-descriptor-utils.js" ;
32import type { OpenClawConfig } from "../config/config.js" ;
4- import { loadConfig } from "../config/config.js" ;
5- import { applyPluginAutoEnable } from "../config/plugin-auto-enable.js" ;
6- import { createSubsystemLogger } from "../logging/subsystem.js" ;
73import type { PluginLoadOptions } from "./loader.js" ;
84import { loadOpenClawPluginCliRegistry , loadOpenClawPlugins } from "./loader.js" ;
95import type { PluginRegistry } from "./registry.js" ;
6+ import {
7+ buildPluginRuntimeLoadOptions ,
8+ createPluginRuntimeLoaderLogger ,
9+ resolvePluginRuntimeLoadContext ,
10+ type PluginRuntimeLoadContext ,
11+ } from "./runtime/load-context.js" ;
1012import type {
1113 OpenClawPluginCliCommandDescriptor ,
1214 OpenClawPluginCliContext ,
1315 PluginLogger ,
1416} from "./types.js" ;
1517
16- const log = createSubsystemLogger ( "plugins" ) ;
17-
1818export type PluginCliLoaderOptions = Pick < PluginLoadOptions , "pluginSdkResolution" > ;
1919
2020export type PluginCliPublicLoadParams = {
@@ -24,13 +24,7 @@ export type PluginCliPublicLoadParams = {
2424 logger ?: PluginLogger ;
2525} ;
2626
27- export type PluginCliLoadContext = {
28- rawConfig : OpenClawConfig ;
29- config : OpenClawConfig ;
30- autoEnabledReasons : Readonly < Record < string , string [ ] > > ;
31- workspaceDir : string | undefined ;
32- logger : PluginLogger ;
33- } ;
27+ export type PluginCliLoadContext = PluginRuntimeLoadContext ;
3428
3529export type PluginCliRegistryLoadResult = PluginCliLoadContext & {
3630 registry : PluginRegistry ;
@@ -44,12 +38,7 @@ export type PluginCliCommandGroupEntry = {
4438} ;
4539
4640export function createPluginCliLogger ( ) : PluginLogger {
47- return {
48- info : ( message : string ) => log . info ( message ) ,
49- warn : ( message : string ) => log . warn ( message ) ,
50- error : ( message : string ) => log . error ( message ) ,
51- debug : ( message : string ) => log . debug ( message ) ,
52- } ;
41+ return createPluginRuntimeLoaderLogger ( ) ;
5342}
5443
5544function resolvePluginCliLogger ( logger ?: PluginLogger ) : PluginLogger {
@@ -80,59 +69,42 @@ function mergeCliRegistrars(params: {
8069
8170function buildPluginCliLoaderParams (
8271 context : PluginCliLoadContext ,
83- env ?: NodeJS . ProcessEnv ,
8472 loaderOptions ?: PluginCliLoaderOptions ,
8573) {
86- return {
87- config : context . config ,
88- activationSourceConfig : context . rawConfig ,
89- autoEnabledReasons : context . autoEnabledReasons ,
90- workspaceDir : context . workspaceDir ,
91- env,
92- logger : context . logger ,
93- ...loaderOptions ,
94- } ;
74+ return buildPluginRuntimeLoadOptions ( context , loaderOptions ) ;
9575}
9676
9777export function resolvePluginCliLoadContext ( params : {
9878 cfg ?: OpenClawConfig ;
9979 env ?: NodeJS . ProcessEnv ;
10080 logger : PluginLogger ;
10181} ) : PluginCliLoadContext {
102- const rawConfig = params . cfg ?? loadConfig ( ) ;
103- const autoEnabled = applyPluginAutoEnable ( { config : rawConfig , env : params . env ?? process . env } ) ;
104- const config = autoEnabled . config ;
105- const workspaceDir = resolveAgentWorkspaceDir ( config , resolveDefaultAgentId ( config ) ) ;
106- return {
107- rawConfig,
108- config,
109- autoEnabledReasons : autoEnabled . autoEnabledReasons ,
110- workspaceDir,
82+ return resolvePluginRuntimeLoadContext ( {
83+ config : params . cfg ,
84+ env : params . env ,
11185 logger : params . logger ,
112- } ;
86+ } ) ;
11387}
11488
11589export async function loadPluginCliMetadataRegistryWithContext (
11690 context : PluginCliLoadContext ,
117- env ?: NodeJS . ProcessEnv ,
11891 loaderOptions ?: PluginCliLoaderOptions ,
11992) : Promise < PluginCliRegistryLoadResult > {
12093 return {
12194 ...context ,
12295 registry : await loadOpenClawPluginCliRegistry (
123- buildPluginCliLoaderParams ( context , env , loaderOptions ) ,
96+ buildPluginCliLoaderParams ( context , loaderOptions ) ,
12497 ) ,
12598 } ;
12699}
127100
128101export async function loadPluginCliCommandRegistryWithContext ( params : {
129102 context : PluginCliLoadContext ;
130- env ?: NodeJS . ProcessEnv ;
131103 loaderOptions ?: PluginCliLoaderOptions ;
132104 onMetadataFallbackError : ( error : unknown ) => void ;
133105} ) : Promise < PluginCliRegistryLoadResult > {
134106 const runtimeRegistry = loadOpenClawPlugins (
135- buildPluginCliLoaderParams ( params . context , params . env , params . loaderOptions ) ,
107+ buildPluginCliLoaderParams ( params . context , params . loaderOptions ) ,
136108 ) ;
137109
138110 if ( ! hasIgnoredAsyncPluginRegistration ( runtimeRegistry ) ) {
@@ -144,7 +116,7 @@ export async function loadPluginCliCommandRegistryWithContext(params: {
144116
145117 try {
146118 const metadataRegistry = await loadOpenClawPluginCliRegistry (
147- buildPluginCliLoaderParams ( params . context , params . env , params . loaderOptions ) ,
119+ buildPluginCliLoaderParams ( params . context , params . loaderOptions ) ,
148120 ) ;
149121 return {
150122 ...params . context ,
@@ -202,7 +174,6 @@ export async function loadPluginCliDescriptors(
202174 } ) ;
203175 const { registry } = await loadPluginCliMetadataRegistryWithContext (
204176 context ,
205- params . env ,
206177 params . loaderOptions ,
207178 ) ;
208179 return collectUniqueCommandDescriptors (
@@ -228,7 +199,6 @@ export async function loadPluginCliRegistrationEntries(params: {
228199 } ) ;
229200 const { config, workspaceDir, logger, registry } = await loadPluginCliCommandRegistryWithContext ( {
230201 context,
231- env : params . env ,
232202 loaderOptions : params . loaderOptions ,
233203 onMetadataFallbackError : params . onMetadataFallbackError ,
234204 } ) ;
0 commit comments