The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): resolve plugin SDK namespaces lazily, not at module scope
g3org3yo6c3d4a4af70d
diff --git a/apps/desktop/src/sdk/runtime.ts b/apps/desktop/src/sdk/runtime.tsindex 449b9060b05..42ba92cce6e 100644--- a/apps/desktop/src/sdk/runtime.ts+++ b/apps/desktop/src/sdk/runtime.ts@@ -13,21 +13,37 @@ import * as jsxRuntime from 'react/jsx-runtime'import * as sdk from './index'-const GLOBALS = {- __HERMES_PLUGIN_SDK__: sdk,- __HERMES_REACT__: React,- __HERMES_REACT_JSX__: jsxRuntime,- __HERMES_REACT_JSX_DEV__: jsxDevRuntime-} as const+// Resolved LAZILY, never as a module-scope literal. This module sits in an+// import cycle — `sdk/index` → `contrib/*` → `contrib/runtime-loader` →+// `sdk/runtime` — so a module-scope `{ __HERMES_PLUGIN_SDK__: sdk, … }` is+// evaluated BEFORE `sdk/index`'s own body runs. In the bundled app that read+// yields `undefined` (the bundler emits the namespace as a hoisted `var`), so+// `Object.keys(GLOBALS.__HERMES_PLUGIN_SDK__)` threw+// "Cannot convert undefined or null to object" and EVERY runtime (disk)+// plugin failed to load. Reading them at call time — installPluginSdk() and+// the shim builder only ever run once the app is up — gets the live+// namespaces.+function pluginNamespaces() {+ return {+ __HERMES_PLUGIN_SDK__: sdk,+ __HERMES_REACT__: React,+ __HERMES_REACT_JSX__: jsxRuntime,+ __HERMES_REACT_JSX_DEV__: jsxDevRuntime+ }+}++type PluginGlobalKey = keyof ReturnType<typeof pluginNamespaces>export function installPluginSdk(): void {- Object.assign(globalThis, GLOBALS)+ Object.assign(globalThis, pluginNamespaces())}/** Build a shim ESM blob that re-exports a global namespace's live members.* Export names come from the namespace itself, so the list can't drift. */-function shimUrl(globalKey: keyof typeof GLOBALS): string {- const names = Object.keys(GLOBALS[globalKey]).filter(name => name !== 'default' && /^[A-Za-z_$][\w$]*$/.test(name))+function shimUrl(globalKey: PluginGlobalKey): string {+ const names = Object.keys(pluginNamespaces()[globalKey]).filter(+ name => name !== 'default' && /^[A-Za-z_$][\w$]*$/.test(name)+ )const source =`const m = globalThis.${globalKey};\n` +