import { fileURLToPath as __fileURLToPath } from 'url';
import { dirname as __pathDirname } from 'path';
const __filename = __fileURLToPath(import.meta.url);
const __dirname = __pathDirname(__filename);
import { TraceDetector } from "./trace-detector.js";
import { v4 as uuidv4 } from "uuid";
const detector = new TraceDetector();
console.log("Trace Detection Demo\n");
console.log("=".repeat(50));
console.log("\n\u{1F4CB} Simulating Search-Driven Modification:");
const baseTime = Date.now();
const searchDrivenTools = [
  {
    id: uuidv4(),
    tool: "search",
    timestamp: baseTime,
    arguments: { query: "authentication bug" }
  },
  {
    id: uuidv4(),
    tool: "grep",
    timestamp: baseTime + 1e3,
    arguments: { pattern: "auth.*error" }
  },
  {
    id: uuidv4(),
    tool: "read",
    timestamp: baseTime + 2e3,
    filesAffected: ["/src/auth/login.ts"]
  },
  {
    id: uuidv4(),
    tool: "edit",
    timestamp: baseTime + 3e3,
    filesAffected: ["/src/auth/login.ts"]
  }
];
searchDrivenTools.forEach((tool) => {
  detector.addToolCall(tool);
  console.log(`  Added: ${tool.tool}`);
});
console.log("\nSimulating Error Recovery:");
const errorTime = baseTime + 4e4;
const errorRecoveryTools = [
  {
    id: uuidv4(),
    tool: "bash",
    timestamp: errorTime,
    arguments: { command: "npm test" },
    error: "Test failed: TypeError"
  },
  {
    id: uuidv4(),
    tool: "edit",
    timestamp: errorTime + 1e3,
    filesAffected: ["/src/utils/validator.ts"]
  },
  {
    id: uuidv4(),
    tool: "bash",
    timestamp: errorTime + 2e3,
    arguments: { command: "npm test" },
    result: "All tests passing"
  }
];
errorRecoveryTools.forEach((tool) => {
  detector.addToolCall(tool);
  console.log(`  Added: ${tool.tool}${tool.error ? " (with error)" : ""}`);
});
console.log("\n\u2728 Simulating Feature Implementation:");
const featureTime = baseTime + 8e4;
const featureTools = [
  {
    id: uuidv4(),
    tool: "write",
    timestamp: featureTime,
    filesAffected: ["/src/components/Dashboard.tsx"]
  },
  {
    id: uuidv4(),
    tool: "edit",
    timestamp: featureTime + 1e3,
    filesAffected: ["/src/components/Dashboard.tsx"]
  },
  {
    id: uuidv4(),
    tool: "test",
    timestamp: featureTime + 2e3,
    arguments: { file: "Dashboard.test.tsx" }
  }
];
featureTools.forEach((tool) => {
  detector.addToolCall(tool);
  console.log(`  Added: ${tool.tool}`);
});
detector.flush();
console.log("\nTrace Statistics:");
console.log("=".repeat(50));
const stats = detector.getStatistics();
console.log(`Total Traces: ${stats.totalTraces}`);
console.log(`Average Score: ${stats.averageScore.toFixed(2)}`);
console.log(`Average Length: ${stats.averageLength.toFixed(1)} tools`);
console.log(`High Importance (>0.7): ${stats.highImportanceCount}`);
console.log("\nTrace Types:");
Object.entries(stats.tracesByType).forEach(([type, count]) => {
  console.log(`  ${type}: ${count}`);
});
console.log("\nDetected Traces:");
console.log("=".repeat(50));
const traces = detector.getTraces();
traces.forEach((trace, index) => {
  console.log(`
Trace ${index + 1}:`);
  console.log(`  Type: ${trace.type}`);
  console.log(`  Score: ${trace.score.toFixed(2)}`);
  console.log(`  Tools: ${trace.tools.map((t) => t.tool).join(" \u2192 ")}`);
  console.log(`  Summary: ${trace.summary}`);
  console.log(
    `  Duration: ${((trace.metadata.endTime - trace.metadata.startTime) / 1e3).toFixed(1)}s`
  );
  if (trace.metadata.filesModified.length > 0) {
    console.log(`  Files Modified: ${trace.metadata.filesModified.join(", ")}`);
  }
  if (trace.metadata.errorsEncountered.length > 0) {
    console.log(`  Errors: ${trace.metadata.errorsEncountered.join(", ")}`);
  }
  if (trace.metadata.causalChain) {
    console.log(`  \u2713 Causal Chain Detected (error\u2192fix\u2192verify)`);
  }
});
console.log("\n\u2B50 High Importance Traces (score > 0.3):");
const highImportance = detector.getHighImportanceTraces(0.3);
highImportance.forEach((trace) => {
  console.log(
    `  [${trace.type}] Score: ${trace.score.toFixed(2)} - ${trace.summary}`
  );
});
console.log("\n\u{1F4BE} Exporting traces to JSON...");
const exported = detector.exportTraces();
console.log(`Exported ${exported.length} characters of JSON data`);
console.log("\nDemo complete!");
//# sourceMappingURL=trace-detector.demo.js.map
