import { ExecutionTraceSchema, type ExecutionTrace } from "../types/executionTrace";

export const SPREADSHEET_EXECUTION_TRACE: ExecutionTrace = ExecutionTraceSchema.parse({
  meta: {
    analysis_id: "execution_trace_spreadsheet_001",
    workflow_template: "research_edit_verify_export",
    generated_at: "2026-03-11T19:07:14Z",
    status: "completed",
    confidence_level: "high",
  },
  run: {
    run_id: "run_spreadsheet_2026_03_11_001",
    workflow_type: "spreadsheet_enrichment",
    user_goal:
      "Evaluate idea directions for Tests Assured, rank them by credibility, and export a cleaned workbook with traceable rationale.",
    status: "completed",
    started_at: "2026-03-11T19:00:00Z",
    completed_at: "2026-03-11T19:07:14Z",
  },
  inputs: {
    uploaded_files: ["/mnt/data/Project 3 2026 Ideas.xlsx"],
    instructions: [
      "Fill and refine idea rows in the workbook.",
      "Anchor recommendations to public reputation rather than unsupported pedigree.",
      "Add traceable rationale, comments, and verification before exporting the result.",
    ],
  },
  steps: [
    {
      step_id: "step_001",
      stage: "ingest",
      type: "task_started",
      title: "Started spreadsheet enrichment run",
      tool: "nodebench_runtime",
      action: "initialize_workflow",
      target: "Project 3 2026 Ideas.xlsx",
      result_summary: "Registered the workbook task as a research-edit-verify-export workflow.",
      confidence: 0.99,
    },
    {
      step_id: "step_002",
      stage: "inspect",
      type: "file_loaded",
      title: "Loaded workbook and enumerated sheets",
      tool: "openpyxl",
      action: "load_workbook",
      target: "/mnt/data/Project 3 2026 Ideas.xlsx",
      result_summary: "Loaded workbook successfully and found one sheet named Sheet1.",
      artifacts_out: ["artifact_input_workbook"],
      confidence: 0.99,
    },
    {
      step_id: "step_003",
      stage: "inspect",
      type: "sheet_inspected",
      title: "Inspected workbook structure and headers",
      tool: "openpyxl",
      action: "read_workbook_structure",
      target: "Sheet1!A1:K40",
      result_summary:
        "Detected 1000 rows, 11 columns, and core headers for idea name, description, target industry, customers, difficulty, timing, competitors, revenue model, and infrastructure cost.",
      confidence: 0.99,
    },
    {
      step_id: "step_004",
      stage: "inspect",
      type: "format_detected",
      title: "Captured workbook formatting baseline",
      tool: "openpyxl",
      action: "inspect_cell_styles",
      target: "Sheet1 header row and column dimensions",
      result_summary:
        "Confirmed bold centered header row, existing column widths, and an empty K column suitable for a recommendation summary.",
      confidence: 0.94,
    },
    {
      step_id: "step_005",
      stage: "verify",
      type: "render_generated",
      title: "Rendered the original workbook",
      tool: "artifact_tool",
      action: "render_spreadsheet",
      target: "/mnt/data/Project 3 2026 Ideas.xlsx",
      result_summary:
        "Rendered the initial sheet to verify layout, blank rows, and available space before editing.",
      artifacts_out: ["artifact_initial_render"],
      verification: ["Initial render completed successfully and showed large blank area below the first three idea rows."],
      confidence: 0.95,
    },
    {
      step_id: "step_006",
      stage: "research",
      type: "research_query_executed",
      title: "Gathered public reputation evidence on Tests Assured",
      tool: "web_search",
      action: "collect_public_positioning",
      target: "Tests Assured public positioning and Meta relationship",
      result_summary:
        "Collected publicly supported signals around immersive-tech QA, wearables, mobile companion apps, sensors, AI-driven automation, and a broad Meta-related relationship.",
      evidence_refs: ["evidence_tests_assured_public", "evidence_tests_assured_meta"],
      confidence: 0.83,
    },
    {
      step_id: "step_007",
      stage: "research",
      type: "evidence_attached",
      title: "Attached truth-boundary evidence",
      tool: "nodebench_runtime",
      action: "record_evidence_catalog",
      target: "Public company evidence set",
      result_summary:
        "Recorded verified and unverified claims so the workbook recommendation stays inside the company's believable adjacency.",
      evidence_refs: ["evidence_tests_assured_public", "evidence_tests_assured_meta", "evidence_aatral_xr"],
      confidence: 0.9,
    },
    {
      step_id: "step_008",
      stage: "propose",
      type: "decision_recorded",
      title: "Ranked ideas by credibility and adjacency",
      tool: "nodebench_runtime",
      action: "rank_product_directions",
      target: "Workbook rows 2-4",
      result_summary:
        "Promoted the agentic QA control plane as the primary recommendation, placed the private device lab as a strong supporting module, and marked the XR sandbox concept as exploratory only.",
      evidence_refs: ["evidence_tests_assured_public", "evidence_tests_assured_meta", "evidence_aatral_xr"],
      confidence: 0.88,
    },
    {
      step_id: "step_009",
      stage: "edit",
      type: "cells_updated",
      title: "Filled recommendation content into the workbook",
      tool: "openpyxl",
      action: "write_ranked_rows",
      target: "Sheet1!A2:K4",
      result_summary:
        "Populated three ranked ideas, added the recommendation column, and rewrote descriptions, industry fit, customer targets, difficulty, revenue, and infrastructure notes.",
      artifacts_out: ["artifact_workbook_draft"],
      confidence: 0.98,
    },
    {
      step_id: "step_010",
      stage: "edit",
      type: "comment_added",
      title: "Added source comments to the idea rows",
      tool: "openpyxl",
      action: "attach_comments",
      target: "Sheet1!A2:A4",
      result_summary:
        "Inserted source comments with plain-text URLs and caveats on what is publicly supported versus inferred.",
      evidence_refs: ["evidence_tests_assured_public", "evidence_tests_assured_meta", "evidence_aatral_xr"],
      confidence: 0.95,
    },
    {
      step_id: "step_011",
      stage: "edit",
      type: "style_changed",
      title: "Applied formatting and navigation helpers",
      tool: "openpyxl",
      action: "format_workbook",
      target: "Sheet1 row heights, widths, fills, freeze panes, and filter range",
      result_summary:
        "Set wrapped top-aligned content, widened columns for readability, colored the recommendation column, froze row 1, and added an autofilter across A1:K4.",
      confidence: 0.96,
    },
    {
      step_id: "step_012",
      stage: "verify",
      type: "render_generated",
      title: "Rendered the edited workbook for QA",
      tool: "artifact_tool",
      action: "render_spreadsheet",
      target: "/mnt/data/Project 3 2026 Ideas_filled.xlsx",
      result_summary:
        "Generated a rendered preview of the edited workbook to check formatting, legibility, and unexpected carryover styles.",
      artifacts_out: ["artifact_render_after_edit"],
      verification: ["Rendered image showed a residual hyperlink style on E3 inherited from the source sheet."],
      confidence: 0.94,
    },
    {
      step_id: "step_013",
      stage: "verify",
      type: "issue_detected",
      title: "Detected hyperlink residue from the source workbook",
      tool: "openpyxl",
      action: "inspect_cell_hyperlink_and_style",
      target: "Sheet1!E3",
      result_summary:
        "Found an inherited Mozilla hyperlink and blue-link styling that no longer matched the rewritten content.",
      artifacts_out: ["artifact_hyperlink_inspection"],
      confidence: 0.97,
    },
    {
      step_id: "step_014",
      stage: "edit",
      type: "issue_fixed",
      title: "Removed the residual hyperlink and restored normal styling",
      tool: "openpyxl",
      action: "clear_hyperlink_and_reset_style",
      target: "Sheet1!E3",
      result_summary:
        "Removed the hyperlink, reset the style to normal, and preserved wrap alignment so the edited text no longer looked like a live link.",
      artifacts_out: ["artifact_workbook_fixed"],
      verification: ["Cell E3 now uses plain text styling and no hyperlink metadata."],
      confidence: 0.99,
    },
    {
      step_id: "step_015",
      stage: "verify",
      type: "verification_passed",
      title: "Re-rendered and confirmed the final workbook",
      tool: "artifact_tool",
      action: "recalculate_and_render",
      target: "/mnt/data/Project 3 2026 Ideas_filled.xlsx",
      result_summary:
        "Re-rendered the workbook after cleanup and confirmed the final layout, comments, fills, and recommendation framing were correct.",
      artifacts_out: ["artifact_final_render"],
      verification: [
        "Render passed after hyperlink cleanup.",
        "Final workbook stayed within the intended reputation and evidence constraints.",
      ],
      confidence: 0.97,
    },
    {
      step_id: "step_016",
      stage: "export",
      type: "artifact_exported",
      title: "Exported the finished workbook",
      tool: "openpyxl",
      action: "save_workbook",
      target: "/mnt/data/Project 3 2026 Ideas_filled.xlsx",
      result_summary: "Saved the completed workbook with comments, formatting, and final content edits.",
      artifacts_out: ["output_workbook"],
      confidence: 0.99,
    },
    {
      step_id: "step_017",
      stage: "summarize",
      type: "task_completed",
      title: "Closed the run with a traceable summary",
      tool: "nodebench_runtime",
      action: "finalize_execution_trace",
      target: "Workflow summary",
      result_summary:
        "Recorded the final recommendation, verification passes, residual limitation notes, and exported artifacts as a structured execution trace instead of raw hidden reasoning.",
      confidence: 0.98,
    },
  ],
  evidence_catalog: [
    {
      evidence_id: "evidence_tests_assured_public",
      title: "Tests Assured public positioning",
      summary:
        "Company materials support immersive-tech QA, smart wearables, mobile companion app testing, cameras/sensors testing, and AI-driven automation.",
      source_refs: [
        { label: "Tests Assured home page", url: "https://testsassured.com/", source_type: "company_website" },
        {
          label: "Tests Assured services page",
          url: "https://testsassured.com/services/",
          source_type: "company_website",
        },
      ],
      supported_claims: [
        "immersive-tech QA expertise",
        "wearables and sensors testing",
        "AI-driven automation positioning",
      ],
      unsupported_claims: [],
    },
    {
      evidence_id: "evidence_tests_assured_meta",
      title: "Meta-related relationship evidence",
      summary:
        "Public materials support a broad Meta-related relationship, but do not disclose exact contract scope or whether a specific agentic QA mobile automation product was delivered.",
      source_refs: [
        {
          label: "PR Newswire brand reference",
          url: "https://www.prnewswire.com/",
          source_type: "press_release",
        },
        {
          label: "Tests Assured brand reference",
          url: "https://testsassured.com/home/",
          source_type: "company_website",
        },
      ],
      supported_claims: ["broad Meta-related relationship"],
      unsupported_claims: ["formal contract for agentic QA automation for Meta mobile apps"],
    },
    {
      evidence_id: "evidence_aatral_xr",
      title: "XR training adjacency",
      summary:
        "BusinessWire coverage of Tests Assured and Aatral supports XR training and simulation adjacency, but not a robotics-company positioning.",
      source_refs: [
        {
          label: "BusinessWire Aatral partnership",
          url: "https://www.businesswire.com/news/home/20230531005465/en/Tests-Assured-Partners-with-Aatral-to-Provide-World-Class-Training-Infrastructure-Using-VRAR-Model",
          source_type: "press_release",
        },
      ],
      supported_claims: ["XR training and simulation adjacency"],
      unsupported_claims: ["general robotics identity"],
    },
  ],
  decisions: [
    {
      decision_id: "decision_001",
      decision_type: "ranking_choice",
      statement: "Promoted the Agentic QA Control Plane as the primary recommendation for Tests Assured.",
      basis: [
        "It best matches the public reputation in immersive-tech QA, wearables, sensors, and mobile companion apps.",
        "It is the easiest story to defend to customers without implying a robotics pivot.",
        "It aligns with the strongest publicly supported Meta-adjacent interpretation without inventing a specific contract scope.",
      ],
      evidence_refs: ["evidence_tests_assured_public", "evidence_tests_assured_meta"],
      alternatives_considered: [
        "Private Device Lab + Secure QA Data Plane",
        "XR Simulation / Training Sandbox",
      ],
    },
    {
      decision_id: "decision_002",
      decision_type: "reputation_guardrail",
      statement: "Marked the XR sandbox idea as exploratory only and explicitly rejected a robotics-company framing.",
      basis: [
        "The public portfolio supports XR and training adjacency but not a general robotics pedigree.",
        "The user explicitly wanted to avoid a future customer asking why the company pivoted without prior expertise.",
      ],
      evidence_refs: ["evidence_aatral_xr", "evidence_tests_assured_meta"],
      alternatives_considered: ["Lead publicly with robotics or world-model training language"],
    },
  ],
  diffs: [
    {
      diff_id: "diff_001",
      target: "Sheet1!A2:K4",
      summary: "Filled the top three idea rows with ranked recommendations and added a recommendation column.",
      cell_changes: [
        {
          cell: "A2",
          before: "QA AI Robotics",
          after: "QA AI Robotics (Reframed: Agentic QA Control Plane)",
        },
        {
          cell: "A3",
          before: "AI Private Network",
          after: "AI Private Network (Private Device Lab + Secure QA Data Plane)",
        },
        {
          cell: "A4",
          before: "Gamefied AI Agent Villages",
          after: "Gamified AI Agent Villages (Reframed: XR Simulation / Training Sandbox)",
        },
        {
          cell: "K1",
          before: null,
          after: "Reputation Fit / Recommendation",
        },
      ],
      structural_changes: [
        "Added source comments to A2:A4.",
        "Applied autofilter to A1:K4.",
        "Froze panes at A2.",
      ],
    },
    {
      diff_id: "diff_002",
      target: "Sheet1!E3",
      summary: "Fixed a residual hyperlink from the original workbook.",
      cell_changes: [
        {
          cell: "E3",
          before: "Existing QA consulting clients... with inherited Mozilla hyperlink styling",
          after: "Existing QA consulting clients... with plain text styling and no hyperlink metadata",
        },
      ],
      structural_changes: ["Reset E3 style to Normal and re-applied wrapped alignment."],
    },
  ],
  verification_checks: [
    {
      check_id: "verify_001",
      label: "Workbook structure inspection passed",
      status: "passed",
      details: "The input workbook loaded cleanly and exposed one editable sheet with usable headers.",
      related_artifact_ids: ["artifact_input_workbook"],
    },
    {
      check_id: "verify_002",
      label: "Initial workbook render passed",
      status: "passed",
      details: "The original workbook rendered before any edits, confirming the baseline layout.",
      related_artifact_ids: ["artifact_initial_render"],
    },
    {
      check_id: "verify_003",
      label: "Residual hyperlink issue detected",
      status: "warning",
      details: "The first edited render exposed an inherited hyperlink and blue-link styling on E3.",
      related_artifact_ids: ["artifact_render_after_edit", "artifact_hyperlink_inspection"],
    },
    {
      check_id: "verify_004",
      label: "Residual hyperlink issue fixed",
      status: "fixed",
      details: "Removed the hyperlink metadata and restored normal styling on E3.",
      related_artifact_ids: ["artifact_workbook_fixed"],
    },
    {
      check_id: "verify_005",
      label: "Final workbook render passed",
      status: "passed",
      details: "The exported workbook rendered cleanly with the intended recommendation framing, comments, and styling.",
      related_artifact_ids: ["artifact_final_render", "output_workbook"],
    },
  ],
  limitations: [
    "Public evidence supported a broad Meta-related relationship, but not a specific contract for agentic mobile QA automation.",
    "The recommendation ranking was bounded by public evidence and user notes, not internal financials or private delivery history.",
    "The execution trace stores actions, evidence, diffs, and verification, not hidden chain-of-thought.",
  ],
  outputs: [
    {
      output_id: "output_workbook",
      label: "Filled workbook export",
      kind: "xlsx",
      path: "/mnt/data/Project 3 2026 Ideas_filled.xlsx",
      summary: "Final workbook with ranked recommendations, source comments, formatting cleanup, and verification passes.",
    },
    {
      output_id: "output_render",
      label: "Final rendered workbook preview",
      kind: "png",
      path: "/tmp/granola_render_spreadsheetg0ij3ekf/Sheet1__auto.png",
      summary: "Rendered preview used to confirm the final workbook layout and cleanup after the hyperlink fix.",
    },
  ],
});
