87 lines
2.4 KiB
TypeScript
87 lines
2.4 KiB
TypeScript
import { assertEquals } from "https://deno.land/std@0.224.0/testing/asserts.ts";
|
|
|
|
/**
|
|
* Proof of Concept: Telemetry parsing (Gen 2)
|
|
*
|
|
* Demonstrates the Analyst agent's ability to ingest structured JSON telemetry
|
|
* by simulating reading actual files from disk rather than hardcoded mock variables.
|
|
*/
|
|
|
|
async function readTelemetry(filePath: string) {
|
|
const data = await Deno.readTextFile(filePath);
|
|
return JSON.parse(data);
|
|
}
|
|
|
|
function analyzeFriction(telemetry: any): string[] {
|
|
const flags = [];
|
|
if (telemetry.metrics.idleHandoffDuration > 4) {
|
|
flags.push(
|
|
"High idle handoff duration detected. Workflow optimization required.",
|
|
);
|
|
}
|
|
if (telemetry.metrics.prCommentToCodeRatio > 0.5) {
|
|
flags.push(
|
|
"High comment-to-code ratio. Potential ambiguity in requirements.",
|
|
);
|
|
}
|
|
return flags;
|
|
}
|
|
|
|
function findPerformanceBottlenecks(trace: any): string[] {
|
|
return trace.spans
|
|
.filter((span: any) => span.duration_ms > 100)
|
|
.map((span: any) => `Bottleneck in ${span.name}: ${span.duration_ms}ms`);
|
|
}
|
|
|
|
if (import.meta.main) {
|
|
console.log("Running Telemetry Parsing PoC (Gen 2) tests...");
|
|
|
|
try {
|
|
const tempFriction = await Deno.makeTempFile({ suffix: ".json" });
|
|
const tempTrace = await Deno.makeTempFile({ suffix: ".json" });
|
|
|
|
await Deno.writeTextFile(
|
|
tempFriction,
|
|
JSON.stringify({
|
|
sprint: "Sprint 42",
|
|
metrics: {
|
|
meanTimeToResolution: 14.5,
|
|
prCommentToCodeRatio: 0.8,
|
|
idleHandoffDuration: 5.2,
|
|
},
|
|
}),
|
|
);
|
|
|
|
await Deno.writeTextFile(
|
|
tempTrace,
|
|
JSON.stringify({
|
|
traceId: "5b8aa5a2d2c8646c14e4d97e6cdbc134",
|
|
spans: [
|
|
{ name: "db_query", duration_ms: 250 },
|
|
{ name: "serialize_json", duration_ms: 12 },
|
|
{ name: "http_request", duration_ms: 300 },
|
|
],
|
|
}),
|
|
);
|
|
|
|
const frictionData = await readTelemetry(tempFriction);
|
|
const traceData = await readTelemetry(tempTrace);
|
|
|
|
const frictionFlags = analyzeFriction(frictionData);
|
|
assertEquals(frictionFlags.length, 2);
|
|
|
|
const bottlenecks = findPerformanceBottlenecks(traceData);
|
|
assertEquals(bottlenecks.length, 2);
|
|
|
|
await Deno.remove(tempFriction);
|
|
await Deno.remove(tempTrace);
|
|
|
|
console.log(
|
|
"✅ Telemetry Parsing PoC (Gen 2) successful: Parsed telemetry from files.",
|
|
);
|
|
} catch (err) {
|
|
console.error("❌ Telemetry Parsing PoC (Gen 2) failed:", err);
|
|
Deno.exit(1);
|
|
}
|
|
}
|