From 7bbca2fdebef3fa2b81dd22e659236b9d92648c6 Mon Sep 17 00:00:00 2001 From: Shawn Morreau Date: Tue, 18 Nov 2025 20:18:00 -0500 Subject: [PATCH] remove slop --- agents/codex.ts | 26 ++++-------------------- agents/cursor.ts | 11 ++--------- agents/gemini.ts | 11 ++--------- agents/shared.ts | 51 +++++++++++++++++++++++++++++++++++------------- 4 files changed, 45 insertions(+), 54 deletions(-) diff --git a/agents/codex.ts b/agents/codex.ts index 88b99ec..52de896 100644 --- a/agents/codex.ts +++ b/agents/codex.ts @@ -1,9 +1,8 @@ import { spawnSync } from "node:child_process"; -import type { McpStdioServerConfig } from "@anthropic-ai/claude-agent-sdk"; import { Codex, type CodexOptions, type ThreadEvent } from "@openai/codex-sdk"; import { log } from "../utils/cli.ts"; import { addInstructions } from "./instructions.ts"; -import { agent, installFromNpmTarball } from "./shared.ts"; +import { agent, type ConfigureMcpServersParams, installFromNpmTarball } from "./shared.ts"; export const codex = agent({ name: "codex", @@ -16,22 +15,11 @@ export const codex = agent({ }); }, run: async ({ prompt, mcpServers, apiKey, cliPath, githubInstallationToken }) => { - // Configure MCP servers if provided - if (mcpServers && Object.keys(mcpServers).length > 0) { - // Filter to only stdio servers - const stdioServers: Record = {}; - for (const [serverName, serverConfig] of Object.entries(mcpServers)) { - if ("command" in serverConfig) { - stdioServers[serverName] = serverConfig; - } - } - if (Object.keys(stdioServers).length > 0) { - configureCodexMcpServers({ mcpServers: stdioServers, cliPath }); - } - } process.env.OPENAI_API_KEY = apiKey; process.env.GITHUB_INSTALLATION_TOKEN = githubInstallationToken; + configureCodexMcpServers({ mcpServers, cliPath }); + // Configure Codex const codexOptions: CodexOptions = { apiKey, @@ -173,13 +161,7 @@ const messageHandlers: { * Configure MCP servers for Codex using the CLI. * Codex CLI syntax: codex mcp add --env KEY=value -- [args...] */ -function configureCodexMcpServers({ - mcpServers, - cliPath, -}: { - mcpServers: Record; - cliPath: string; -}): void { +function configureCodexMcpServers({ mcpServers, cliPath }: ConfigureMcpServersParams): void { for (const [serverName, serverConfig] of Object.entries(mcpServers)) { const command = serverConfig.command; const args = serverConfig.args || []; diff --git a/agents/cursor.ts b/agents/cursor.ts index ad027f1..aa6508d 100644 --- a/agents/cursor.ts +++ b/agents/cursor.ts @@ -1,10 +1,9 @@ import { spawn } from "node:child_process"; import { mkdirSync, writeFileSync } from "node:fs"; import { join } from "node:path"; -import type { McpStdioServerConfig } from "@anthropic-ai/claude-agent-sdk"; import { log } from "../utils/cli.ts"; import { addInstructions } from "./instructions.ts"; -import { agent, installFromCurl } from "./shared.ts"; +import { agent, type ConfigureMcpServersParams, installFromCurl } from "./shared.ts"; export const cursor = agent({ name: "cursor", @@ -122,13 +121,7 @@ export const cursor = agent({ * Configure MCP servers for Cursor by writing to the Cursor configuration file. * For cursor, we need to add the MCP servers to the Cursor configuration file manually as there is no CLI command to do this. */ -function configureCursorMcpServers({ - mcpServers, - cliPath, -}: { - mcpServers: Record; - cliPath: string; -}) { +function configureCursorMcpServers({ mcpServers, cliPath }: ConfigureMcpServersParams) { const tempDir = cliPath.split("/.local/bin/")[0]; const cursorConfigDir = join(tempDir, ".cursor"); const mcpConfigPath = join(cursorConfigDir, "mcp.json"); diff --git a/agents/gemini.ts b/agents/gemini.ts index ba4ea1c..3890b61 100644 --- a/agents/gemini.ts +++ b/agents/gemini.ts @@ -1,9 +1,8 @@ import { spawnSync } from "node:child_process"; -import type { McpStdioServerConfig } from "@anthropic-ai/claude-agent-sdk"; import { log } from "../utils/cli.ts"; import { spawn } from "../utils/subprocess.ts"; import { addInstructions } from "./instructions.ts"; -import { agent, installFromNpmTarball } from "./shared.ts"; +import { agent, type ConfigureMcpServersParams, installFromNpmTarball } from "./shared.ts"; export const gemini = agent({ name: "gemini", @@ -87,13 +86,7 @@ export const gemini = agent({ * Configure MCP servers for Gemini using the CLI. * Gemini CLI syntax: gemini mcp add [args...] --env KEY=value */ -function configureGeminiMcpServers({ - mcpServers, - cliPath, -}: { - mcpServers: Record; - cliPath: string; -}): void { +function configureGeminiMcpServers({ mcpServers, cliPath }: ConfigureMcpServersParams): void { for (const [serverName, serverConfig] of Object.entries(mcpServers)) { const command = serverConfig.command; const args = serverConfig.args || []; diff --git a/agents/shared.ts b/agents/shared.ts index ac7c81e..0d43741 100644 --- a/agents/shared.ts +++ b/agents/shared.ts @@ -28,6 +28,40 @@ export interface AgentConfig { cliPath: string; } +/** + * Parameters for configuring MCP servers + */ +export interface ConfigureMcpServersParams { + mcpServers: Record; + cliPath: string; +} + +/** + * Parameters for installing from npm tarball + */ +export interface InstallFromNpmTarballParams { + packageName: string; + version: string; + executablePath: string; + installDependencies?: boolean; +} + +/** + * Parameters for installing from curl script + */ +export interface InstallFromCurlParams { + installUrl: string; + executableName: string; +} + +/** + * NPM registry response data structure + */ +export interface NpmRegistryData { + "dist-tags": { latest: string }; + versions: Record; +} + /** * Install a CLI tool from an npm package tarball * Downloads the tarball, extracts it to a temp directory, and returns the path to the CLI executable @@ -38,12 +72,7 @@ export async function installFromNpmTarball({ version, executablePath, installDependencies, -}: { - packageName: string; - version: string; - executablePath: string; - installDependencies?: boolean; -}): Promise { +}: InstallFromNpmTarballParams): Promise { // Resolve version if it's a range or "latest" let resolvedVersion = version; if (version.startsWith("^") || version.startsWith("~") || version === "latest") { @@ -54,10 +83,7 @@ export async function installFromNpmTarball({ if (!registryResponse.ok) { throw new Error(`Failed to query registry: ${registryResponse.status}`); } - const registryData = (await registryResponse.json()) as { - "dist-tags": { latest: string }; - versions: Record; - }; + const registryData = (await registryResponse.json()) as NpmRegistryData; resolvedVersion = registryData["dist-tags"].latest; log.info(`Resolved to version ${resolvedVersion}`); } catch (error) { @@ -153,10 +179,7 @@ export async function installFromNpmTarball({ export async function installFromCurl({ installUrl, executableName, -}: { - installUrl: string; - executableName: string; -}): Promise { +}: InstallFromCurlParams): Promise { log.info(`📦 Installing ${executableName}...`); // Derive temp directory prefix from executable name (sanitize similar to package name)