improve logging

This commit is contained in:
David Blass
2025-10-31 01:58:43 -04:00
parent 434458a068
commit 15a7154aea
13 changed files with 132 additions and 142 deletions
+7 -48
View File
@@ -1,56 +1,17 @@
import * as core from "@actions/core";
import { query, type SDKMessage } from "@anthropic-ai/claude-agent-sdk";
import { createMcpConfig } from "../mcp/config.ts";
import { log } from "../utils/cli.ts";
import { debugLog, isDebug } from "../utils/logging.ts";
import { instructions } from "./shared.ts";
import type { Agent, AgentConfig, AgentResult } from "./types.ts";
/**
* Claude Code agent implementation
*/
export class ClaudeAgent implements Agent {
private apiKey: string;
private githubInstallationToken: string;
constructor(config: AgentConfig) {
this.apiKey = config.apiKey;
this.githubInstallationToken = config.githubInstallationToken;
}
/**
* Install is a no-op since Claude CLI is bundled with the SDK
*/
async install(): Promise<void> {
// No installation needed - CLI is bundled with @anthropic-ai/claude-agent-sdk
}
/**
* Execute Claude Code with the given prompt using the SDK
*/
async execute(prompt: string): Promise<AgentResult> {
log.info("Running Claude Agent SDK...");
log.box(prompt, { title: "Prompt" });
const mcpConfig = JSON.parse(createMcpConfig(this.githubInstallationToken));
if (isDebug()) {
debugLog(`📋 MCP Config: ${JSON.stringify(mcpConfig, null, 2)}`);
}
// Initialize session
core.info(`🚀 Starting Claude Agent SDK session...`);
// Set API key environment variable for SDK
process.env.ANTHROPIC_API_KEY = this.apiKey;
import type { Agent } from "./types.ts";
export const claude: Agent = {
run: async ({ prompt, mcpServers, apiKey }) => {
process.env.ANTHROPIC_API_KEY = apiKey;
// Create the query with SDK options
const queryInstance = query({
prompt: `${instructions}\n\n${prompt}`,
options: {
permissionMode: "bypassPermissions",
mcpServers: mcpConfig.mcpServers,
mcpServers,
},
});
@@ -60,14 +21,12 @@ export class ClaudeAgent implements Agent {
await handler(message as never);
}
log.success("Task complete.");
return {
success: true,
output: "",
};
}
}
},
};
type SDKMessageType = SDKMessage["type"];
+8 -17
View File
@@ -1,19 +1,4 @@
/**
* Standard interface for all Pullfrog agents
*/
export interface Agent {
/**
* Install the agent and any required dependencies
*/
install(): Promise<void>;
/**
* Execute the agent with the given prompt
* @param prompt The prompt to send to the agent
* @param options Additional options specific to the agent
*/
execute(prompt: string, options?: Record<string, any>): Promise<AgentResult>;
}
import type { McpServerConfig } from "@anthropic-ai/claude-agent-sdk";
/**
* Result returned by agent execution
@@ -22,7 +7,7 @@ export interface AgentResult {
success: boolean;
output?: string;
error?: string;
metadata?: Record<string, any>;
metadata?: Record<string, unknown>;
}
/**
@@ -31,4 +16,10 @@ export interface AgentResult {
export interface AgentConfig {
apiKey: string;
githubInstallationToken: string;
prompt: string;
mcpServers: Record<string, McpServerConfig>;
}
export type Agent = {
run: (config: AgentConfig) => Promise<AgentResult>;
};