diff --git a/main.ts b/main.ts index e82c18c..7fd5e38 100644 --- a/main.ts +++ b/main.ts @@ -23,6 +23,7 @@ import { setupGitHubInstallationToken, } from "./utils/github.ts"; import { setupGitAuth, setupGitBranch, setupGitConfig } from "./utils/setup.ts"; +import { Timer } from "./utils/timer.ts"; // runtime validation using agents (needed for ArkType) // Note: The AgentName type is defined in external.ts, this is the runtime validator @@ -53,23 +54,34 @@ export async function main(inputs: Inputs): Promise { let mcpServerClose: (() => Promise) | undefined; try { + const timer = new Timer(); + // parse payload early to extract agent const payload = parsePayload(inputs); const partialCtx = await initializeContext(inputs, payload); const ctx = partialCtx as MainContext; + timer.checkpoint("initializeContext"); setupGitAuth({ githubInstallationToken: ctx.githubInstallationToken, repoContext: ctx.repoContext, }); + await setupTempDirectory(ctx); + timer.checkpoint("setupTempDirectory"); setupGitBranch(ctx.payload); + await startMcpServer(ctx); mcpServerClose = ctx.mcpServerClose; + timer.checkpoint("startMcpServer"); + setupMcpServers(ctx); + await installAgentCli(ctx); + timer.checkpoint("installAgentCli"); + await validateApiKey(ctx); const result = await runAgent(ctx); diff --git a/mcp/comment.ts b/mcp/comment.ts index 4f16951..0aec463 100644 --- a/mcp/comment.ts +++ b/mcp/comment.ts @@ -245,9 +245,15 @@ export async function ensureProgressCommentUpdated(): Promise { // check if MCP context is initialized (MCP server started) try { const ctx = getMcpContext(); - const errorMessage = `🐸 this run croaked + const repoContext = parseRepoContext(); + const runId = process.env.GITHUB_RUN_ID; + const workflowRunLink = runId + ? `[workflow](https://github.com/${repoContext.owner}/${repoContext.name}/actions/runs/${runId})` + : "workflow"; -The workflow encountered an error before any progress could be reported. Please check the workflow run logs for details.`; + const errorMessage = `❌ this run croaked + +The workflow encountered an error before any progress could be reported. Please check the ${workflowRunLink} for details.`; const bodyWithFooter = addFooter(errorMessage, ctx.payload); diff --git a/utils/timer.ts b/utils/timer.ts new file mode 100644 index 0000000..c6f023a --- /dev/null +++ b/utils/timer.ts @@ -0,0 +1,21 @@ +import { log } from "./cli.ts"; + +export class Timer { + private initialTimestamp: number; + private lastCheckpointTimestamp: number | null = null; + + constructor() { + this.initialTimestamp = Date.now(); + } + + checkpoint(name: string): void { + const now = Date.now(); + const duration = this.lastCheckpointTimestamp + ? now - this.lastCheckpointTimestamp + : now - this.initialTimestamp; + + log.info(`${name}: ${duration}ms`); + this.lastCheckpointTimestamp = now; + } +} +