From 065d364ffb00145c72b723733825baa205cb4fd6 Mon Sep 17 00:00:00 2001 From: bft-codebot Date: Thu, 26 Feb 2026 19:29:27 +0000 Subject: [PATCH] sync(bfmono): fix(gambit): handle non-file import.meta.url in jsr runtime paths (+19 more) (bfmono@eee085e1c) This PR is an automated gambitmono sync of bfmono Gambit packages. - Source: `packages/gambit/` - Core: `packages/gambit/packages/gambit-core/` - bfmono rev: eee085e1c Changes: - eee085e1c fix(gambit): handle non-file import.meta.url in jsr runtime paths - fe98813a6 fix(gambit): replace dynamic import.meta.resolve at runtime - 68953d21c chore(gambit): release 0.8.5 - 175e49006 fix(gambit-core): support non-file import.meta.url at runtime init - 3c44ef51a fix(gambit): include core snippets/decks/workers in compile assets - 591734506 fix(gambit): exclude .codex from Build file listing - 4fe56b200 chore(gambit): cut 0.8.5-rc.12 - 2bfffaaae fix(gambit): add codex trust preflight for workbench chat - 9c16505d6 chore(gambit): cut 0.8.5-rc.11 - b4d5cdaef fix(simulator-ui): prevent feedback reason text from being clobbered - 84952a652 fix(gambit-verify): align verify turn labels and stabilize initial run filtering - c56b7f52f feat(gambit): improve verify report controls and harden concurrent calibrate persistence - beb9435c0 feat(gambit-simulator-ui): extend listbox trigger and popover options - 25f9fdcfc fix(gambit-simulator-ui): align verify outlier chip semantics and display - a010b0ee1 feat(gambit-simulator-ui): add verify outliers to workbench chat chips - 383f2500a refactor(simulator-ui): replace nested ternaries in main routing - 13c4c8c22 fix(gambit): preserve shared references in safe session serialization - ae392aa24 feat(gambit-simulator-ui): add grader error chips to workbench chat - 1de6b335c fix(gambit): clamp deck-level maxTurns bounds in test run selection - 01d7abbb9 fix(gambit): default verify tab bootstrap flag to enabled Do not edit this repo directly; make changes in bfmono and re-run the sync. --- packages/gambit-core/src/runtime.ts | 9 ++++++--- src/cli_args.ts | 4 ++-- src/commands/scaffold_utils.ts | 13 ++++++++++++- src/providers/codex.ts | 18 +++++++++++++----- src/server.ts | 14 +++++++------- 5 files changed, 40 insertions(+), 18 deletions(-) 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 {