remove slop

This commit is contained in:
Shawn Morreau
2025-11-18 20:18:00 -05:00
parent 0ac4975b50
commit 7bbca2fdeb
4 changed files with 45 additions and 54 deletions
+4 -22
View File
@@ -1,9 +1,8 @@
import { spawnSync } from "node:child_process"; 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 { Codex, type CodexOptions, type ThreadEvent } from "@openai/codex-sdk";
import { log } from "../utils/cli.ts"; import { log } from "../utils/cli.ts";
import { addInstructions } from "./instructions.ts"; import { addInstructions } from "./instructions.ts";
import { agent, installFromNpmTarball } from "./shared.ts"; import { agent, type ConfigureMcpServersParams, installFromNpmTarball } from "./shared.ts";
export const codex = agent({ export const codex = agent({
name: "codex", name: "codex",
@@ -16,22 +15,11 @@ export const codex = agent({
}); });
}, },
run: async ({ prompt, mcpServers, apiKey, cliPath, githubInstallationToken }) => { 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<string, McpStdioServerConfig> = {};
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.OPENAI_API_KEY = apiKey;
process.env.GITHUB_INSTALLATION_TOKEN = githubInstallationToken; process.env.GITHUB_INSTALLATION_TOKEN = githubInstallationToken;
configureCodexMcpServers({ mcpServers, cliPath });
// Configure Codex // Configure Codex
const codexOptions: CodexOptions = { const codexOptions: CodexOptions = {
apiKey, apiKey,
@@ -173,13 +161,7 @@ const messageHandlers: {
* Configure MCP servers for Codex using the CLI. * Configure MCP servers for Codex using the CLI.
* Codex CLI syntax: codex mcp add <name> --env KEY=value -- <command> [args...] * Codex CLI syntax: codex mcp add <name> --env KEY=value -- <command> [args...]
*/ */
function configureCodexMcpServers({ function configureCodexMcpServers({ mcpServers, cliPath }: ConfigureMcpServersParams): void {
mcpServers,
cliPath,
}: {
mcpServers: Record<string, McpStdioServerConfig>;
cliPath: string;
}): void {
for (const [serverName, serverConfig] of Object.entries(mcpServers)) { for (const [serverName, serverConfig] of Object.entries(mcpServers)) {
const command = serverConfig.command; const command = serverConfig.command;
const args = serverConfig.args || []; const args = serverConfig.args || [];
+2 -9
View File
@@ -1,10 +1,9 @@
import { spawn } from "node:child_process"; import { spawn } from "node:child_process";
import { mkdirSync, writeFileSync } from "node:fs"; import { mkdirSync, writeFileSync } from "node:fs";
import { join } from "node:path"; import { join } from "node:path";
import type { McpStdioServerConfig } from "@anthropic-ai/claude-agent-sdk";
import { log } from "../utils/cli.ts"; import { log } from "../utils/cli.ts";
import { addInstructions } from "./instructions.ts"; import { addInstructions } from "./instructions.ts";
import { agent, installFromCurl } from "./shared.ts"; import { agent, type ConfigureMcpServersParams, installFromCurl } from "./shared.ts";
export const cursor = agent({ export const cursor = agent({
name: "cursor", name: "cursor",
@@ -122,13 +121,7 @@ export const cursor = agent({
* Configure MCP servers for Cursor by writing to the Cursor configuration file. * 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. * 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({ function configureCursorMcpServers({ mcpServers, cliPath }: ConfigureMcpServersParams) {
mcpServers,
cliPath,
}: {
mcpServers: Record<string, McpStdioServerConfig>;
cliPath: string;
}) {
const tempDir = cliPath.split("/.local/bin/")[0]; const tempDir = cliPath.split("/.local/bin/")[0];
const cursorConfigDir = join(tempDir, ".cursor"); const cursorConfigDir = join(tempDir, ".cursor");
const mcpConfigPath = join(cursorConfigDir, "mcp.json"); const mcpConfigPath = join(cursorConfigDir, "mcp.json");
+2 -9
View File
@@ -1,9 +1,8 @@
import { spawnSync } from "node:child_process"; import { spawnSync } from "node:child_process";
import type { McpStdioServerConfig } from "@anthropic-ai/claude-agent-sdk";
import { log } from "../utils/cli.ts"; import { log } from "../utils/cli.ts";
import { spawn } from "../utils/subprocess.ts"; import { spawn } from "../utils/subprocess.ts";
import { addInstructions } from "./instructions.ts"; import { addInstructions } from "./instructions.ts";
import { agent, installFromNpmTarball } from "./shared.ts"; import { agent, type ConfigureMcpServersParams, installFromNpmTarball } from "./shared.ts";
export const gemini = agent({ export const gemini = agent({
name: "gemini", name: "gemini",
@@ -87,13 +86,7 @@ export const gemini = agent({
* Configure MCP servers for Gemini using the CLI. * Configure MCP servers for Gemini using the CLI.
* Gemini CLI syntax: gemini mcp add <name> <commandOrUrl> [args...] --env KEY=value * Gemini CLI syntax: gemini mcp add <name> <commandOrUrl> [args...] --env KEY=value
*/ */
function configureGeminiMcpServers({ function configureGeminiMcpServers({ mcpServers, cliPath }: ConfigureMcpServersParams): void {
mcpServers,
cliPath,
}: {
mcpServers: Record<string, McpStdioServerConfig>;
cliPath: string;
}): void {
for (const [serverName, serverConfig] of Object.entries(mcpServers)) { for (const [serverName, serverConfig] of Object.entries(mcpServers)) {
const command = serverConfig.command; const command = serverConfig.command;
const args = serverConfig.args || []; const args = serverConfig.args || [];
+37 -14
View File
@@ -28,6 +28,40 @@ export interface AgentConfig {
cliPath: string; cliPath: string;
} }
/**
* Parameters for configuring MCP servers
*/
export interface ConfigureMcpServersParams {
mcpServers: Record<string, McpStdioServerConfig>;
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<string, unknown>;
}
/** /**
* Install a CLI tool from an npm package tarball * 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 * 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, version,
executablePath, executablePath,
installDependencies, installDependencies,
}: { }: InstallFromNpmTarballParams): Promise<string> {
packageName: string;
version: string;
executablePath: string;
installDependencies?: boolean;
}): Promise<string> {
// Resolve version if it's a range or "latest" // Resolve version if it's a range or "latest"
let resolvedVersion = version; let resolvedVersion = version;
if (version.startsWith("^") || version.startsWith("~") || version === "latest") { if (version.startsWith("^") || version.startsWith("~") || version === "latest") {
@@ -54,10 +83,7 @@ export async function installFromNpmTarball({
if (!registryResponse.ok) { if (!registryResponse.ok) {
throw new Error(`Failed to query registry: ${registryResponse.status}`); throw new Error(`Failed to query registry: ${registryResponse.status}`);
} }
const registryData = (await registryResponse.json()) as { const registryData = (await registryResponse.json()) as NpmRegistryData;
"dist-tags": { latest: string };
versions: Record<string, unknown>;
};
resolvedVersion = registryData["dist-tags"].latest; resolvedVersion = registryData["dist-tags"].latest;
log.info(`Resolved to version ${resolvedVersion}`); log.info(`Resolved to version ${resolvedVersion}`);
} catch (error) { } catch (error) {
@@ -153,10 +179,7 @@ export async function installFromNpmTarball({
export async function installFromCurl({ export async function installFromCurl({
installUrl, installUrl,
executableName, executableName,
}: { }: InstallFromCurlParams): Promise<string> {
installUrl: string;
executableName: string;
}): Promise<string> {
log.info(`📦 Installing ${executableName}...`); log.info(`📦 Installing ${executableName}...`);
// Derive temp directory prefix from executable name (sanitize similar to package name) // Derive temp directory prefix from executable name (sanitize similar to package name)