From 0311130a8ab6dddd92df8412635edaf8e98550c7 Mon Sep 17 00:00:00 2001 From: gsxdsm Date: Thu, 12 Mar 2026 19:30:17 -0700 Subject: [PATCH] fix: Update @github/copilot-sdk version and enhance version utility to locate package.json (#840) - Changed @github/copilot-sdk dependency from "^0.1.16" to "0.1.16" in package.json and package-lock.json. - Improved version utility in version.ts to check multiple candidate paths for package.json, ensuring better reliability in locating the file. --- .gitignore | 1 + apps/server/package.json | 2 +- apps/server/src/lib/version.ts | 17 ++++- apps/ui/src/electron/server/backend-server.ts | 64 ++++++++++++------- package-lock.json | 2 +- 5 files changed, 58 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index e9cb3275..1c2d1a32 100644 --- a/.gitignore +++ b/.gitignore @@ -113,3 +113,4 @@ data/ .planning/ .mcp.json .planning +.bg-shell/ \ No newline at end of file diff --git a/apps/server/package.json b/apps/server/package.json index 8fc0f5de..a552ff11 100644 --- a/apps/server/package.json +++ b/apps/server/package.json @@ -32,7 +32,7 @@ "@automaker/prompts": "1.0.0", "@automaker/types": "1.0.0", "@automaker/utils": "1.0.0", - "@github/copilot-sdk": "^0.1.16", + "@github/copilot-sdk": "0.1.16", "@modelcontextprotocol/sdk": "1.25.2", "@openai/codex-sdk": "^0.98.0", "cookie-parser": "1.4.7", diff --git a/apps/server/src/lib/version.ts b/apps/server/src/lib/version.ts index 93d88d48..9fd8eeec 100644 --- a/apps/server/src/lib/version.ts +++ b/apps/server/src/lib/version.ts @@ -2,7 +2,7 @@ * Version utility - Reads version from package.json */ -import { readFileSync } from 'fs'; +import { readFileSync, existsSync } from 'fs'; import { fileURLToPath } from 'url'; import { dirname, join } from 'path'; import { createLogger } from '@automaker/utils'; @@ -24,7 +24,20 @@ export function getVersion(): string { } try { - const packageJsonPath = join(__dirname, '..', '..', 'package.json'); + const candidatePaths = [ + // Development via tsx: src/lib -> project root + join(__dirname, '..', '..', 'package.json'), + // Packaged/build output: lib -> server bundle root + join(__dirname, '..', 'package.json'), + ]; + + const packageJsonPath = candidatePaths.find((candidate) => existsSync(candidate)); + if (!packageJsonPath) { + throw new Error( + `package.json not found in any expected location: ${candidatePaths.join(', ')}` + ); + } + const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8')); const version = packageJson.version || '0.0.0'; cachedVersion = version; diff --git a/apps/ui/src/electron/server/backend-server.ts b/apps/ui/src/electron/server/backend-server.ts index 8fd6358b..1921d232 100644 --- a/apps/ui/src/electron/server/backend-server.ts +++ b/apps/ui/src/electron/server/backend-server.ts @@ -28,33 +28,46 @@ const serverLogger = createLogger('Server'); export async function startServer(): Promise { const isDev = !app.isPackaged; - // Find Node.js executable (handles desktop launcher scenarios) - const nodeResult = findNodeExecutable({ - skipSearch: isDev, - logger: (msg: string) => logger.info(msg), - }); - const command = nodeResult.nodePath; - - // Validate that the found Node executable actually exists - // systemPathExists is used because node-finder returns system paths - if (command !== 'node') { - let exists: boolean; - try { - exists = systemPathExists(command); - } catch (error) { - const originalError = error instanceof Error ? error.message : String(error); - throw new Error( - `Failed to verify Node.js executable at: ${command} (source: ${nodeResult.source}). Reason: ${originalError}` - ); - } - if (!exists) { - throw new Error(`Node.js executable not found at: ${command} (source: ${nodeResult.source})`); - } - } - + let command: string; + let commandSource: string; let args: string[]; let serverPath: string; + if (isDev) { + // In development, run the TypeScript server via the user's Node.js. + const nodeResult = findNodeExecutable({ + skipSearch: true, + logger: (msg: string) => logger.info(msg), + }); + command = nodeResult.nodePath; + commandSource = nodeResult.source; + + // Validate that the found Node executable actually exists + // systemPathExists is used because node-finder returns system paths + if (command !== 'node') { + let exists: boolean; + try { + exists = systemPathExists(command); + } catch (error) { + const originalError = error instanceof Error ? error.message : String(error); + throw new Error( + `Failed to verify Node.js executable at: ${command} (source: ${nodeResult.source}). Reason: ${originalError}` + ); + } + if (!exists) { + throw new Error( + `Node.js executable not found at: ${command} (source: ${nodeResult.source})` + ); + } + } + } else { + // In packaged builds, use Electron's bundled Node runtime instead of a system Node. + // This makes the desktop app self-contained and avoids incompatibilities with whatever + // Node version the user happens to have installed globally. + command = process.execPath; + commandSource = 'electron'; + } + // __dirname is apps/ui/dist-electron (Vite bundles all into single file) if (isDev) { serverPath = path.join(__dirname, '../../server/src/index.ts'); @@ -133,6 +146,8 @@ export async function startServer(): Promise { PORT: state.serverPort.toString(), DATA_DIR: dataDir, NODE_PATH: serverNodeModules, + // Run packaged backend with Electron's embedded Node runtime. + ...(app.isPackaged && { ELECTRON_RUN_AS_NODE: '1' }), // Pass API key to server for CSRF protection AUTOMAKER_API_KEY: state.apiKey!, // Only set ALLOWED_ROOT_DIRECTORY if explicitly provided in environment @@ -146,6 +161,7 @@ export async function startServer(): Promise { logger.info('[DATA_DIR_SPAWN] env.DATA_DIR=', env.DATA_DIR); logger.info('Starting backend server...'); + logger.info('Runtime command:', command, `(source: ${commandSource})`); logger.info('Server path:', serverPath); logger.info('Server root (cwd):', serverRoot); logger.info('NODE_PATH:', serverNodeModules); diff --git a/package-lock.json b/package-lock.json index d1d9d868..65a6cde1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -44,7 +44,7 @@ "@automaker/prompts": "1.0.0", "@automaker/types": "1.0.0", "@automaker/utils": "1.0.0", - "@github/copilot-sdk": "^0.1.16", + "@github/copilot-sdk": "0.1.16", "@modelcontextprotocol/sdk": "1.25.2", "@openai/codex-sdk": "^0.98.0", "cookie-parser": "1.4.7",