diff --git a/packages/mcp-server/src/index.ts b/packages/mcp-server/src/index.ts index 086c2b5e..cdb5b931 100644 --- a/packages/mcp-server/src/index.ts +++ b/packages/mcp-server/src/index.ts @@ -95,8 +95,7 @@ export { main as startMcpServer }; // More robust check that works with npx and direct execution const isMainModule = import.meta.url === `file://${process.argv[1]}` || - process.argv[1]?.endsWith('ade-workflows-server') || - process.argv[1]?.endsWith('index.js'); + process.argv[1]?.endsWith('ade-workflows-server'); if (isMainModule) { await main().catch(error => { diff --git a/packages/opencode-plugin/tsup.config.ts b/packages/opencode-plugin/tsup.config.ts index af0da03a..747ad49a 100644 --- a/packages/opencode-plugin/tsup.config.ts +++ b/packages/opencode-plugin/tsup.config.ts @@ -1,4 +1,8 @@ import { defineConfig } from 'tsup'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); export default defineConfig({ entry: { @@ -22,4 +26,20 @@ export default defineConfig({ ], target: 'node20', sourcemap: false, + esbuildOptions(options) { + // Resolve @codemcp/workflows-server from its source entry point so that + // esbuild can deduplicate @codemcp/workflows-core across both the server + // and the direct imports in this package. Without this, the pre-built + // dist/index.js of @codemcp/workflows-server already contains an inlined + // copy of @codemcp/workflows-core, and esbuild bundles a second copy for + // the direct imports here — resulting in two separate logSinkInstance + // globals that prevent the OpenCode log sink from being shared. + options.alias = { + ...options.alias, + '@codemcp/workflows-server': path.resolve( + __dirname, + '../mcp-server/src/index.ts' + ), + }; + }, });