diff --git a/src/channels/plugins/read-only-command-defaults.ts b/src/channels/plugins/read-only-command-defaults.ts index e4b8d6c9c01..15337d33dfd 100644 --- a/src/channels/plugins/read-only-command-defaults.ts +++ b/src/channels/plugins/read-only-command-defaults.ts @@ -1,5 +1,6 @@ import type { OpenClawConfig } from "../../config/types.openclaw.js"; import { isBlockedObjectKey } from "../../infra/prototype-keys.js"; +import { getCurrentPluginMetadataSnapshot } from "../../plugins/current-plugin-metadata-snapshot.js"; import { isInstalledPluginEnabled } from "../../plugins/installed-plugin-index.js"; import type { PluginManifestRecord } from "../../plugins/manifest-registry.js"; import { loadPluginMetadataSnapshot } from "../../plugins/plugin-metadata-snapshot.js"; @@ -64,17 +65,28 @@ export function resolveReadOnlyChannelCommandDefaults( if (!normalizedChannelId || !isSafeManifestChannelId(normalizedChannelId)) { return undefined; } - const snapshot = loadPluginMetadataSnapshot({ - config: options.config, - stateDir: options.stateDir, - workspaceDir: options.workspaceDir, - env: options.env ?? process.env, - }); - for (const record of snapshot.plugins) { + const env = options.env ?? process.env; + const snapshot = + options.stateDir === undefined + ? getCurrentPluginMetadataSnapshot({ + config: options.config, + env, + workspaceDir: options.workspaceDir, + }) + : undefined; + const resolvedSnapshot = + snapshot ?? + loadPluginMetadataSnapshot({ + config: options.config, + stateDir: options.stateDir, + workspaceDir: options.workspaceDir, + env, + }); + for (const record of resolvedSnapshot.plugins) { if (!record.channels.includes(normalizedChannelId)) { continue; } - if (!isInstalledPluginEnabled(snapshot.index, record.id, options.config)) { + if (!isInstalledPluginEnabled(resolvedSnapshot.index, record.id, options.config)) { continue; } const channelConfigValue = record.channelConfigs diff --git a/src/channels/plugins/read-only.ts b/src/channels/plugins/read-only.ts index c2ba51767ed..44520c42064 100644 --- a/src/channels/plugins/read-only.ts +++ b/src/channels/plugins/read-only.ts @@ -10,6 +10,7 @@ import { listConfiguredChannelIdsForReadOnlyScope, resolveDiscoverableScopedChannelPluginIds, } from "../../plugins/channel-plugin-ids.js"; +import { getCurrentPluginMetadataSnapshot } from "../../plugins/current-plugin-metadata-snapshot.js"; import { channelPluginIdBelongsToManifest, resolveSetupChannelRegistration, @@ -697,12 +698,22 @@ export function resolveReadOnlyChannelPluginsForConfig( ): ReadOnlyChannelPluginResolution { const env = options.env ?? process.env; const workspaceDir = resolveReadOnlyWorkspaceDir(cfg, options); - const manifestRecords = loadPluginMetadataSnapshot({ - config: cfg, - stateDir: options.stateDir, - workspaceDir, - env, - }).plugins; + const metadataSnapshot = + options.stateDir === undefined + ? getCurrentPluginMetadataSnapshot({ + config: cfg, + env, + workspaceDir, + }) + : undefined; + const manifestRecords = + metadataSnapshot?.plugins ?? + loadPluginMetadataSnapshot({ + config: cfg, + stateDir: options.stateDir, + workspaceDir, + env, + }).plugins; const bundledManifestRecords = listBundledChannelManifestRecords(manifestRecords); const externalManifestRecords = listExternalChannelManifestRecords(manifestRecords); const configuredChannelIds = [