add more codex logic

This commit is contained in:
Shawn Morreau
2025-11-12 19:22:48 -05:00
parent 71698d3e07
commit 7aaebe9584
9 changed files with 948 additions and 907 deletions
+21 -33
View File
@@ -1,9 +1,7 @@
import { type } from "arktype";
import { claude } from "./agents/claude.ts";
import { codex } from "./agents/codex.ts";
import { createMcpConfigs } from "./mcp/config.ts";
import packageJson from "./package.json" with { type: "json" };
import { DEFAULT_REPO_SETTINGS, getRepoSettings, type RepoSettings } from "./utils/api.ts";
import { fetchRepoSettings } from "./utils/api.ts";
import { log } from "./utils/cli.ts";
import {
parseRepoContext,
@@ -11,12 +9,16 @@ import {
setupGitHubInstallationToken,
} from "./utils/github.ts";
import { setupGitAuth, setupGitConfig } from "./utils/setup.ts";
import { agents } from "./agents/index.ts";
export const AgentName = type.enumerated("codex", "claude");
export type AgentName = typeof AgentName.infer;
export const Inputs = type({
prompt: "string",
"anthropic_api_key?": "string | undefined",
"openai_api_key?": "string | undefined",
"agent?": "string | undefined",
"agent?": AgentName,
});
export type Inputs = typeof Inputs.infer;
@@ -35,6 +37,7 @@ export async function main(inputs: Inputs): Promise<MainResult> {
try {
log.info(`🐸 Running pullfrog/action@${packageJson.version}...`);
Inputs.assert(inputs);
setupGitConfig();
const { githubInstallationToken, wasAcquired, isFallbackToken } =
@@ -44,31 +47,15 @@ export async function main(inputs: Inputs): Promise<MainResult> {
}
const repoContext = parseRepoContext();
// Fetch repo settings (agent, permissions, workflows) from API
// Skip API call if we're using GITHUB_TOKEN fallback (app not installed)
let repoSettings: RepoSettings;
if (isFallbackToken) {
log.info("Using default repository settings (app not installed)");
repoSettings = DEFAULT_REPO_SETTINGS;
} else {
log.info("Fetching repository settings...");
repoSettings = await getRepoSettings(githubInstallationToken, repoContext);
log.info("Repository settings fetched");
}
// Use agent from inputs if provided, otherwise use repo settings, default to claude
const agent = inputs.agent || repoSettings.defaultAgent || "claude";
// Agent registry
const agents = {
claude,
codex,
} as const;
const repoSettings = await fetchRepoSettings({
token: githubInstallationToken,
repoContext,
isFallbackToken,
});
if (!(agent in agents)) {
throw new Error(`Unsupported agent: ${agent}. Supported agents: ${Object.keys(agents).join(", ")}`);
}
const agentName: AgentName = inputs.agent || repoSettings.defaultAgent || "claude";
const agentImpl = agents[agent as keyof typeof agents];
const agent = agents[agentName];
setupGitAuth(githubInstallationToken, repoContext);
@@ -77,9 +64,9 @@ export async function main(inputs: Inputs): Promise<MainResult> {
log.debug(`📋 MCP Config: ${JSON.stringify(mcpServers, null, 2)}`);
// Install agent CLI before running
await agentImpl.install();
const cliPath = await agent.install();
log.info(`Running ${agent} Agent SDK...`);
log.info(`Running ${agentName} Agent SDK...`);
log.box(inputs.prompt, { title: "Prompt" });
// TODO: check if `inputs.prompts` is JSON
@@ -88,25 +75,26 @@ export async function main(inputs: Inputs): Promise<MainResult> {
// Get API key based on agent type
let apiKey: string;
if (agent === "claude") {
if (agentName === "claude") {
if (!inputs.anthropic_api_key) {
throw new Error("ANTHROPIC_API_KEY is required for Claude agent");
}
apiKey = inputs.anthropic_api_key;
} else if (agent === "codex") {
} else if (agentName === "codex") {
if (!inputs.openai_api_key) {
throw new Error("OPENAI_API_KEY is required for Codex agent");
}
apiKey = inputs.openai_api_key;
} else {
throw new Error(`API key configuration not implemented for agent: ${agent}`);
throw new Error(`API key configuration not implemented for agent: ${agentName}`);
}
const result = await agentImpl.run({
const result = await agent.run({
prompt: inputs.prompt,
mcpServers,
githubInstallationToken,
apiKey,
cliPath,
});
if (!result.success) {