MCPcopy Create free account
hub / github.com/cli/cli / observe

Function observe

evals/src/core/observer.ts:6–21  ·  view source on GitHub ↗
(calls: Call[], value: unknown, now: number)

Source from the content-addressed store, hash-verified

4import { writeFile } from "node:fs/promises";
5
6export function observe(calls: Call[], value: unknown, now: number): void {
7 const event = record(value);
8 if (event.type !== "tool.execution_start" && event.type !== "tool.execution_complete") return;
9 const data = record(event.data);
10 if (typeof data.toolCallId !== "string") throw new Error("SDK tool event is missing its call ID");
11 const id = `tool:${data.toolCallId}`;
12 if (event.type === "tool.execution_start") {
13 if (calls.some(call => call.id === id)) throw new Error("Duplicate SDK tool call ID");
14 calls.push({ id, kind: "tool", arguments: data.arguments, startedAt: now });
15 } else {
16 const call = calls.find(item => item.id === id);
17 if (!call) throw new Error("SDK completed an unknown tool call");
18 call.endedAt = now;
19 call.success = data.success === true;
20 }
21}
22
23export class CommandObserver {
24 private readonly server: Server;

Callers 2

harness.test.tsFile · 0.85
trialMethod · 0.85

Calls 3

pushMethod · 0.80
findMethod · 0.80
recordFunction · 0.70

Tested by

no test coverage detected