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 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<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.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 <name> --env KEY=value -- <command> [args...]
*/
function configureCodexMcpServers({
mcpServers,
cliPath,
}: {
mcpServers: Record<string, McpStdioServerConfig>;
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 || [];
+2 -9
View File
@@ -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<string, McpStdioServerConfig>;
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");
+2 -9
View File
@@ -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 <name> <commandOrUrl> [args...] --env KEY=value
*/
function configureGeminiMcpServers({
mcpServers,
cliPath,
}: {
mcpServers: Record<string, McpStdioServerConfig>;
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 || [];
+37 -14
View File
@@ -28,6 +28,40 @@ export interface AgentConfig {
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
* 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<string> {
}: InstallFromNpmTarballParams): Promise<string> {
// 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<string, unknown>;
};
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<string> {
}: InstallFromCurlParams): Promise<string> {
log.info(`📦 Installing ${executableName}...`);
// Derive temp directory prefix from executable name (sanitize similar to package name)