diff --git a/packages/gambit-core/src/runtime.ts b/packages/gambit-core/src/runtime.ts index b0fb8f22..64028000 100644 --- a/packages/gambit-core/src/runtime.ts +++ b/packages/gambit-core/src/runtime.ts @@ -3022,19 +3022,22 @@ function collectLocalImportGraph(entryPath: string): Set { return visited; } -const moduleBaseFilePath = (() => { +const moduleBaseUrl = (() => { try { - return path.fromFileUrl(import.meta.url); + return new URL(import.meta.url); } catch { return undefined; } })(); +const moduleBaseFilePath = moduleBaseUrl?.protocol === "file:" + ? path.fromFileUrl(moduleBaseUrl) + : undefined; const WORKER_ENTRY_PATHS = moduleBaseFilePath ? [ "./runtime_worker.ts", "./runtime_orchestration_worker.ts", - ].map((relative) => path.fromFileUrl(new URL(relative, import.meta.url))) + ].map((relative) => path.fromFileUrl(new URL(relative, moduleBaseUrl))) : []; const BUILTIN_SCHEMAS_DIR = moduleBaseFilePath ? path.resolve(path.dirname(moduleBaseFilePath), "../schemas") diff --git a/src/cli_args.ts b/src/cli_args.ts index 4f9cf3d7..a19dc1af 100644 --- a/src/cli_args.ts +++ b/src/cli_args.ts @@ -308,8 +308,8 @@ type CommandDoc = { function resolveBundledPath(specifier: string): string | null { try { - const resolved = import.meta.resolve(specifier); - if (resolved.startsWith("file:")) { + const resolved = new URL(specifier, import.meta.url); + if (resolved.protocol === "file:") { return path.fromFileUrl(resolved); } } catch { diff --git a/src/commands/scaffold_utils.ts b/src/commands/scaffold_utils.ts index 07ea77ac..b21c6ea4 100644 --- a/src/commands/scaffold_utils.ts +++ b/src/commands/scaffold_utils.ts @@ -7,7 +7,18 @@ const logger = console; export type ScaffoldKind = "demo"; function resolveCandidate(specifier: string): string | undefined { - const url = new URL(import.meta.resolve(specifier)); + let resolvedSpecifier: string; + try { + resolvedSpecifier = import.meta.resolve(specifier); + } catch { + try { + resolvedSpecifier = new URL(specifier, import.meta.url).href; + } catch { + return undefined; + } + } + + const url = new URL(resolvedSpecifier); if (url.protocol !== "file:") return undefined; const candidatePath = path.fromFileUrl(url); try { diff --git a/src/providers/codex.ts b/src/providers/codex.ts index dab1bdba..b510c215 100644 --- a/src/providers/codex.ts +++ b/src/providers/codex.ts @@ -21,10 +21,18 @@ const CODEX_REASONING_SUMMARY_ENV = "GAMBIT_CODEX_REASONING_SUMMARY"; const CODEX_VERBOSITY_ENV = "GAMBIT_CODEX_VERBOSITY"; const CODEX_BIN_ENV = "GAMBIT_CODEX_BIN"; const MCP_ROOT_DECK_PATH_ENV = "GAMBIT_MCP_ROOT_DECK_PATH"; -const MCP_SERVER_PATH = path.resolve( - path.dirname(path.fromFileUrl(import.meta.url)), - "../mcp_server.ts", -); +const MCP_SERVER_PATH = (() => { + try { + const moduleUrl = new URL(import.meta.url); + if (moduleUrl.protocol !== "file:") return null; + return path.resolve( + path.dirname(path.fromFileUrl(moduleUrl)), + "../mcp_server.ts", + ); + } catch { + return null; + } +})(); type CodexTurnUsage = { input_tokens?: unknown; @@ -147,7 +155,7 @@ function codexConfigArgs(input: { args.push("-c", `model_verbosity=${tomlString(verbosity.trim())}`); } - if (shouldEnableMcpBridge()) { + if (shouldEnableMcpBridge() && MCP_SERVER_PATH) { args.push("-c", `mcp_servers.gambit.command=${tomlString("deno")}`); args.push( "-c", diff --git a/src/server.ts b/src/server.ts index ba9d7430..272d00f5 100644 --- a/src/server.ts +++ b/src/server.ts @@ -419,14 +419,14 @@ function cloneValue(value: T): T { } function resolveDeckPath(p: string): string { - const absolutePath = path.isAbsolute(p) ? p : path.resolve(p); - try { - const url = import.meta.resolve(path.toFileUrl(absolutePath).href); - if (url.startsWith("file:")) return path.fromFileUrl(url); - return url; - } catch { - return absolutePath; + if (p.startsWith("file:")) { + try { + return path.fromFileUrl(p); + } catch { + return p; + } } + return path.isAbsolute(p) ? p : path.resolve(p); } function materializeDefaults(schema?: NormalizedSchema): unknown {