Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/gambit-core/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3022,19 +3022,22 @@ function collectLocalImportGraph(entryPath: string): Set<string> {
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")
Expand Down
4 changes: 2 additions & 2 deletions src/cli_args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 12 additions & 1 deletion src/commands/scaffold_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 13 additions & 5 deletions src/providers/codex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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",
Expand Down
14 changes: 7 additions & 7 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,14 +419,14 @@ function cloneValue<T>(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 {
Expand Down