param(
  [string]$OutZip = "gdr8050l_auth_v250_dynamic_iscsi_live_artifacts.zip",
  [string]$LogJsonl = "gdr8050l_auth_v250_stateful_relock_keep_loaded_iscsi_start_live.jsonl"
)
$ErrorActionPreference = "Stop"
$base = [System.IO.Path]::GetFileNameWithoutExtension($LogJsonl)
$resp = "${base}_responses"
$reportJson = "${base}_trace_report.json"
$reportMd = "${base}_trace_report.md"
$handoffJson = "${base}_firmware_handoff_report.json"
$handoffMd = "${base}_firmware_handoff_report.md"
$shadowJson = "${base}_firmware_shadow_3e_report.json"
$shadowMd = "${base}_firmware_shadow_3e_report.md"
$capShadowJson = "${base}_firmware_shadow_capacity_report.json"
$capShadowMd = "${base}_firmware_shadow_capacity_report.md"
$boundsShadowJson = "${base}_firmware_shadow_bounds_report.json"
$boundsShadowMd = "${base}_firmware_shadow_bounds_report.md"
$lbaShadowJson = "${base}_firmware_shadow_lba_map_report.json"
$lbaShadowMd = "${base}_firmware_shadow_lba_map_report.md"
$mediaLayoutJson = "${base}_media_layout_report.json"
$mediaLayoutMd = "${base}_media_layout_report.md"
$mediaSelfJson = "${base}_media_profile_selftest_report.json"
$mediaSelfMd = "${base}_media_profile_selftest_report.md"
$mediaPayloadJson = "${base}_media_payload_integrity_report.json"
$mediaPayloadMd = "${base}_media_payload_integrity_report.md"
$mediaPreflightJson = "${base}_media_profile_preflight_report.json"
$mediaPreflightMd = "${base}_media_profile_preflight_report.md"
$fleetJson = "${base}_local_regression_fleet_report.json"
$fleetMd = "${base}_local_regression_fleet_report.md"
$cpuSweepJson = "${base}_firmware_read_cdb_cpu_sweep_report.json"
$cpuSweepMd = "${base}_firmware_read_cdb_cpu_sweep_report.md"
$cpuSweepCases = "${base}_firmware_read_cdb_cpu_sweep_report_cases"
$cpuSweepLog = "${base}_firmware_read_cdb_cpu_sweep_report.run.log"
$windowProbeJson = "${base}_firmware_window_constant_probe_report.json"
$windowProbeMd = "${base}_firmware_window_constant_probe_report.md"
$deltaAuditJson = "${base}_firmware_window_delta_audit_report.json"
$deltaAuditMd = "${base}_firmware_window_delta_audit_report.md"

$readWindowPathJson = "${base}_firmware_read_window_path_probe_report.json"
$readWindowPathMd = "${base}_firmware_read_window_path_probe_report.md"
$descriptorBuilderJson = "${base}_firmware_descriptor_builder_probe_report.json"
$descriptorBuilderMd = "${base}_firmware_descriptor_builder_probe_report.md"
$descriptorBuilderCases = "${base}_firmware_descriptor_builder_probe_report_cases"
$standardProbeJson = "${base}_standard_probe_coverage_report.json"
$standardProbeMd = "${base}_standard_probe_coverage_report.md"

if (Test-Path $LogJsonl) {
  $args = @("hlds_gdr_iscsi_trace_report.py", $LogJsonl, "--json", $reportJson, "--md", $reportMd)
  if (Test-Path $resp) { $args += @("--response-dir", $resp) }
  python @args
  python hlds_gdr_standard_probe_coverage_report.py $LogJsonl --json $standardProbeJson --md $standardProbeMd
  python hlds_gdr_firmware_handoff_report.py $LogJsonl --json $handoffJson --md $handoffMd --trace-report-json $reportJson
  python hlds_gdr_firmware_shadow_3e_report.py $LogJsonl --json $shadowJson --md $shadowMd
  $capArgs = @("hlds_gdr_firmware_shadow_capacity_report.py", $LogJsonl, "--json", $capShadowJson, "--md", $capShadowMd)
  if (Test-Path $resp) { $capArgs += @("--response-dir", $resp) }
  python @capArgs
  $boundsArgs = @("hlds_gdr_firmware_shadow_bounds_report.py", $LogJsonl, "--json", $boundsShadowJson, "--md", $boundsShadowMd)
  if (Test-Path $resp) { $boundsArgs += @("--response-dir", $resp) }
  python @boundsArgs

  $lbaArgs = @("hlds_gdr_firmware_shadow_lba_map_report.py", $LogJsonl, "--json", $lbaShadowJson, "--md", $lbaShadowMd)
  if (Test-Path $resp) { $lbaArgs += @("--response-dir", $resp) }
  python @lbaArgs

  python hlds_gdr_media_layout_report.py $LogJsonl --json $mediaLayoutJson --md $mediaLayoutMd

  $mediaPreflightArgs = @(
    "hlds_gdr_media_profile_preflight.py",
    "--jsonl", $LogJsonl,
    "--config", "gdr8050l_auth_v250_stateful_relock_keep_loaded_iscsi_config.json",
    "--strict-image",
    "--require-media-profile",
    "--expect-redump",
    "--json", $mediaPreflightJson,
    "--md", $mediaPreflightMd
  )
  python @mediaPreflightArgs

  $mediaSelfArgs = @(
    "hlds_gdr_media_profile_selftest.py",
    "--jsonl", $LogJsonl,
    "--config", "gdr8050l_auth_v250_stateful_relock_keep_loaded_iscsi_config.json",
    "--json", $mediaSelfJson,
    "--md", $mediaSelfMd
  )
  python @mediaSelfArgs

  $mediaPayloadArgs = @(
    "hlds_gdr_media_payload_integrity_report.py",
    "--jsonl", $LogJsonl,
    "--config", "gdr8050l_auth_v250_stateful_relock_keep_loaded_iscsi_config.json",
    "--json", $mediaPayloadJson,
    "--md", $mediaPayloadMd
  )
  if (Test-Path $resp) { $mediaPayloadArgs += @("--response-dir", $resp) }
  python @mediaPayloadArgs

  $fleetArgs = @("hlds_gdr_local_regression_fleet.py", $LogJsonl, "--jsonl", $LogJsonl, "--out-prefix", "${base}", "--json", $fleetJson, "--md", $fleetMd)
  if (Test-Path $resp) { $fleetArgs += @("--response-dir", $resp) }
  python @fleetArgs

  $cpuSweepArgs = @(
    "hlds_gdr_firmware_read_cdb_cpu_sweep.py",
    "--config", "gdr8050l_auth_v250_stateful_relock_keep_loaded_iscsi_config.json",
    "--mn103s-emu", "mn103s_emu.py",
    "--out-prefix", "${base}_firmware_read_cdb_cpu_sweep_report",
    "--case-set", "full",
    "--json", $cpuSweepJson,
    "--md", $cpuSweepMd
  )
  python @cpuSweepArgs

  $windowProbeArgs = @(
    "hlds_gdr_firmware_window_constant_probe.py",
    "--config", "gdr8050l_auth_v250_stateful_relock_keep_loaded_iscsi_config.json",
    "--jsonl", $LogJsonl,
    "--lba-map-json", $lbaShadowJson,
    "--read-cdb-sweep-json", $cpuSweepJson,
    "--json", $windowProbeJson,
    "--md", $windowProbeMd
  )
  python @windowProbeArgs

  $deltaAuditArgs = @(
    "hlds_gdr_firmware_window_delta_audit.py",
    $LogJsonl,
    "--config", "gdr8050l_auth_v250_stateful_relock_keep_loaded_iscsi_config.json",
    "--lba-map-json", $lbaShadowJson,
    "--media-layout-json", $mediaLayoutJson,
    "--window-constant-json", $windowProbeJson,
    "--json", $deltaAuditJson,
    "--md", $deltaAuditMd
  )
  python @deltaAuditArgs

  $descriptorBuilderArgs = @(
    "hlds_gdr_firmware_descriptor_builder_probe.py",
    "--config", "gdr8050l_auth_v250_stateful_relock_keep_loaded_iscsi_config.json",
    "--mn103s-emu", "mn103s_emu.py",
    "--out-prefix", "${base}_firmware_descriptor_builder_probe_report",
    "--json", $descriptorBuilderJson,
    "--md", $descriptorBuilderMd,
    "--case-dir", $descriptorBuilderCases
  )
  python @descriptorBuilderArgs

  $readWindowPathArgs = @(
    "hlds_gdr_firmware_read_window_path_probe.py",
    $LogJsonl,
    "--config", "gdr8050l_auth_v250_stateful_relock_keep_loaded_iscsi_config.json",
    "--read-cdb-sweep-json", $cpuSweepJson,
    "--sweep-case-dir", $cpuSweepCases,
    "--delta-audit-json", $deltaAuditJson,
    "--descriptor-builder-json", $descriptorBuilderJson,
    "--json", $readWindowPathJson,
    "--md", $readWindowPathMd
  )
  python @readWindowPathArgs
} else {
  Write-Host "[WARN] JSONL not found: $LogJsonl"
}
$items = @(
  $LogJsonl,
  "${base}_ready.json",
  $resp,
  $reportJson,
  $reportMd,
  $handoffJson,
  $handoffMd,
  $shadowJson,
  $shadowMd,
  $capShadowJson,
  $capShadowMd,
  $boundsShadowJson,
  $boundsShadowMd,
  $lbaShadowJson,
  $lbaShadowMd,
  $mediaLayoutJson,
  $mediaLayoutMd,
  $mediaSelfJson,
  $mediaSelfMd,
  $mediaPayloadJson,
  $mediaPayloadMd,
  $mediaPreflightJson,
  $mediaPreflightMd,
  $fleetJson,
  $fleetMd,
  $cpuSweepJson,
  $cpuSweepMd,
  $cpuSweepCases,
  $cpuSweepLog,
  $windowProbeJson,
  $windowProbeMd,
  $deltaAuditJson,
  $deltaAuditMd,
  $descriptorBuilderJson,
  $descriptorBuilderMd,
  $descriptorBuilderCases,
  $readWindowPathJson,
  $readWindowPathMd,
  $standardProbeJson,
  $standardProbeMd,
  "gdr8050l_auth_v250_stateful_relock_keep_loaded_iscsi_config.json",
  "gdr8050l_auth_v250_stateful_real_eject_iscsi_config.json",
  "local_validation_v250.md",
  "local_validation_v250_firmware_window_delta_audit_report.json",
  "local_validation_v250_firmware_window_delta_audit_report.md",
  "local_validation_v250_firmware_descriptor_builder_probe_report.json",
  "local_validation_v250_firmware_descriptor_builder_probe_report.md",
  "local_validation_v250_firmware_descriptor_builder_probe_report_cases",
  "local_validation_v250_firmware_read_window_path_probe_report.json",
  "local_validation_v250_firmware_read_window_path_probe_report.md",
  "local_validation_v250_media_profile_preflight_report.md",
  "local_validation_v250_media_payload_integrity_report.md",
  "local_validation_v250_local_regression_fleet_report.md",
  "local_validation_v250_standard_probe_coverage_report.json",
  "local_validation_v250_standard_probe_coverage_report.md",
  "README_v250_gdr8050l_descriptor_builder_microprobe.md"
) | Where-Object { Test-Path $_ }
if ($items.Count -eq 0) { Write-Host "[WARN] no v250 live artifacts found"; exit 1 }
if (Test-Path $OutZip) { Remove-Item -Force $OutZip }
Compress-Archive -Path $items -DestinationPath $OutZip -Force
Write-Host "[OK] wrote $OutZip"
