Refactor action with agent interface system and make anthropic_api_key optional

- Created extensible agent interface with install() and execute() methods
- Moved Claude Code logic to agents/claude.ts implementing Agent interface
- Added utilities directory for reusable functions (exec, files)
- Refactored index.ts to be minimal (35 lines) using agent abstraction
- Made anthropic_api_key optional in action.yml
- Updated Node.js imports to use node: prefix convention
- Bumped version to 0.0.5
- Architecture now supports multiple agents (OpenAI, Gemini, etc.)
This commit is contained in:
Colin McDonnell
2025-08-28 13:37:20 -07:00
parent 6a0d9cc244
commit 1abbd7ff41
10 changed files with 364 additions and 71 deletions
+34 -12
View File
@@ -1,17 +1,39 @@
import * as core from "@actions/core";
import { createAgent } from "./agents/factory";
try {
// Get the message input parameter, with a default fallback
const message = core.getInput("message") || "Hello from Pullfrog Action!";
async function main(): Promise<void> {
try {
// Get inputs
const prompt = core.getInput("prompt", { required: true });
const anthropicApiKey = core.getInput("anthropic_api_key", { required: true });
// Print the message to console and GitHub Actions logs
console.log(`🐸 Pullfrog says: ${message}`);
core.info(`Action executed successfully with message: ${message}`);
if (!anthropicApiKey) {
throw new Error("anthropic_api_key is required");
}
// Set an output for potential use by other actions
core.setOutput("message", message);
} catch (error) {
// Handle any errors and fail the action
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
core.setFailed(`Action failed: ${errorMessage}`);
core.info(`🐸 Pullfrog Claude Code Action starting...`);
core.info(`Prompt: ${prompt}`);
// Create and install the Claude agent
const agent = createAgent("claude", { apiKey: anthropicApiKey });
await agent.install();
// Execute the agent with the prompt
const result = await agent.execute(prompt);
if (!result.success) {
throw new Error(result.error || "Agent execution failed");
}
// Set outputs
core.setOutput("status", "success");
core.setOutput("prompt", prompt);
core.setOutput("output", result.output || "");
} catch (error) {
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
core.setFailed(`Action failed: ${errorMessage}`);
}
}
// Execute main function
main();