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

Function jsonOutput

evals/src/suites/events/grading/observations.ts:15–35  ·  view source on GitHub ↗
(call: GhCall)

Source from the content-addressed store, hash-verified

13}
14
15export function jsonOutput(call: GhCall): Array<{ at: number; value: unknown }> {
16 const chunks = call.output.filter(chunk => chunk.stream === "stdout");
17 const whole = json(chunks.map(chunk => chunk.text).join(""));
18 if (whole !== undefined && chunks.length) return [{ at: chunks.at(-1)!.at, value: whole }];
19 const values: Array<{ at: number; value: unknown }> = [];
20 let pending = "";
21 for (const chunk of chunks) {
22 pending += chunk.text;
23 let newline: number;
24 while ((newline = pending.indexOf("\n")) >= 0) {
25 const value = json(pending.slice(0, newline));
26 if (value !== undefined) values.push({ at: chunk.at, value });
27 pending = pending.slice(newline + 1);
28 }
29 }
30 if (pending.trim() && chunks.length) {
31 const value = json(pending);
32 if (value !== undefined) values.push({ at: chunks.at(-1)!.at, value });
33 }
34 return values;
35}
36
37function containsReview(value: unknown, reviewId: number, expected?: Record<string, unknown>): boolean {
38 if (Array.isArray(value)) return value.some(item => containsReview(item, reviewId, expected));

Callers 2

reviewReadAtFunction · 0.85
observedAtFunction · 0.85

Calls 2

jsonFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected