From 22418b37146dc75437db52f1b86b741e94ddf275 Mon Sep 17 00:00:00 2001 From: Colin McDonnell Date: Thu, 4 Dec 2025 10:56:45 -0800 Subject: [PATCH] Add timer --- main.ts | 12 ++++++++++++ utils/timer.ts | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 utils/timer.ts diff --git a/main.ts b/main.ts index f9d77cf..5ede9d0 100644 --- a/main.ts +++ b/main.ts @@ -21,6 +21,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 @@ -51,23 +52,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"); + validateApiKey(ctx); const result = await runAgent(ctx); 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; + } +} +