have payload.agent take precedence over inputs.defaultAgent

This commit is contained in:
Colin McDonnell
2025-11-20 16:58:21 -08:00
parent b460bd3109
commit dd2089d71b
5 changed files with 34 additions and 15 deletions
+9
View File
@@ -7,6 +7,15 @@ inputs:
description: "Prompt to send to Claude Code"
required: true
default: "Hello from Claude Code!"
defaultAgent:
description: "Default agent to use. Overridden by payload.agent if present."
required: false
type: choice
options:
- claude
- codex
- cursor
- gemini
anthropic_api_key:
description: "Anthropic API key for Claude Code authentication"
required: false
+1 -1
View File
@@ -22,7 +22,7 @@ async function run(): Promise<void> {
try {
const inputs: Required<Inputs> = {
prompt: core.getInput("prompt", { required: true }),
agent: core.getInput("agent") ? AgentName.assert(core.getInput("agent")) : undefined,
defaultAgent: core.getInput("defaultAgent") ? AgentName.assert(core.getInput("defaultAgent")) : undefined,
...flatMorph(agents, (_, agent) =>
agent.apiKeyNames.map((inputKey) => [inputKey, core.getInput(inputKey)])
),
+4
View File
@@ -123,6 +123,10 @@ export type PayloadEvent =
url: string;
};
[key: string]: any;
}
| {
trigger: "unknown";
[key: string]: any;
};
// payload type for agent execution
+16 -13
View File
@@ -35,7 +35,9 @@ const keyInputDefs = flatMorph(agents, (_, agent) =>
export const Inputs = type({
prompt: "string",
...keyInputDefs,
"agent?": type.enumerated(...Object.values(agents).map((agent) => agent.name)).or("undefined"),
"defaultAgent?": type
.enumerated(...Object.values(agents).map((agent) => agent.name))
.or("undefined"),
});
export type Inputs = typeof Inputs.infer;
@@ -51,12 +53,13 @@ export async function main(inputs: Inputs): Promise<MainResult> {
const ctx = partialCtx as MainContext;
try {
// parse payload early to extract agent for determineAgent
ctx.payload = parsePayload(inputs);
await determineAgent(ctx);
setupGitAuth(ctx.githubInstallationToken, ctx.repoContext);
await setupTempDirectory(ctx);
setupMcpLogPolling(ctx);
ctx.payload = parsePayload(inputs);
setupGitBranch(ctx.payload);
setupMcpServers(ctx);
await installAgentCli(ctx);
@@ -73,7 +76,10 @@ export async function main(inputs: Inputs): Promise<MainResult> {
error: errorMessage,
};
} finally {
await cleanup(partialCtx);
await cleanup({
...partialCtx,
payload: ctx.payload,
});
}
}
@@ -167,14 +173,16 @@ async function initializeContext(
}
async function determineAgent(
ctx: Omit<MainContext, "payload" | "mcpServers" | "cliPath" | "apiKey">
ctx: Omit<MainContext, "mcpServers" | "cliPath" | "apiKey">
): Promise<void> {
const repoSettings = await fetchRepoSettings({
token: ctx.githubInstallationToken,
repoContext: ctx.repoContext,
});
ctx.agentName = ctx.inputs.agent || repoSettings.defaultAgent || "claude";
// precedence: payload.agent > inputs.defaultAgent > repoSettings.defaultAgent > "claude"
ctx.agentName =
ctx.payload.agent || ctx.inputs.defaultAgent || repoSettings.defaultAgent || "claude";
ctx.agent = agents[ctx.agentName];
}
@@ -215,11 +223,8 @@ function parsePayload(inputs: Inputs): Payload {
agent: null,
prompt: inputs.prompt,
event: {
trigger: "issues_opened",
issue_number: 0,
issue_title: "",
issue_body: null,
} as Payload["event"],
trigger: "unknown",
},
modes,
};
}
@@ -283,9 +288,7 @@ async function handleAgentResult(
};
}
async function cleanup(
ctx: Omit<MainContext, "payload" | "mcpServers" | "cliPath" | "apiKey">
): Promise<void> {
async function cleanup(ctx: Omit<MainContext, "mcpServers" | "cliPath" | "apiKey">): Promise<void> {
if (ctx.pollInterval) {
clearInterval(ctx.pollInterval);
}
+4 -1
View File
@@ -21,9 +21,12 @@ export async function run(prompt: string): Promise<AgentResult> {
const originalCwd = process.cwd();
process.chdir(tempDir);
// check if prompt is a pullfrog payload and extract agent
// note: agent from payload will be used by determineAgent with highest precedence
// we don't need to extract it here since main() will parse the payload
const inputs: Required<Inputs> = {
prompt,
agent: "codex",
defaultAgent: undefined,
...flatMorph(agents, (_, agent) =>
agent.apiKeyNames.map((inputKey) => [inputKey, process.env[inputKey.toUpperCase()]])
),