# =csv-insights <path>: profile a CSV file you point at.
#
# What this app teaches, in three lines:
# 1. `emits: File` plus an absolute `path` on every row gives Open, Reveal and Preview for free.
# 2. One entity_preview pane shows a Markdown body per row, so a "chart" can be block-character bars.
# 3. The script refuses bad input in a row the person can read (relative path, binary, over 5 MB).
#
# Type =csv-insights then an absolute path (or ~/path). Rows: a Summary (row and
# column counts, null rate, a preview table) and one row per column (type, null
# rate, top values). Tab on a row for "Copy summary" and "Copy column list".
#
# Sample data: `=csv-insights demo`, or no path at all, profiles a small
# fabricated CSV built in memory. Every sample row says SAMPLE DATA. Nothing is
# read from disk for the demo, and this app never writes anywhere.
schema_version: 1
runtime: bridge
id: csv-insights
chip: csv-insights
title: CSV insights
icon: table
description: "Profile a CSV: rows, columns, types, empty cells, top values. =csv-insights demo shows sample data"
placeholder_examples: ["~/Downloads/orders.csv", "demo"]
emits: File

bridge:
  command:
    macos: "python3 {{scripts_dir}}/bolt-csv-insights.py {{query}}"
    linux: "python3 {{scripts_dir}}/bolt-csv-insights.py {{query}}"
    windows: "python {{scripts_dir}}/bolt-csv-insights.py {{query}}"
  parse: json
  timeout_seconds: 12

presentation:
  widget: list
  title_field: title
  subtitle_field: subtitle
  right_widget:
    kind: entity_preview
    mode: selected_row
    bind:
      title: "{{row.title}}"
      subtitle: "{{row.subtitle}}"
      fields:
        - { label: Type, value: "{{row.type}}" }
        - { label: Empty cells, value: "{{row.nulls}}" }
        - { label: Distinct, value: "{{row.distinct}}" }
        - { label: Range, value: "{{row.figure}}" }
      body: "{{row.body}}"
      actions: [copy-summary, copy-columns]

# No `primary: true` on purpose: Enter keeps the file behaviour that
# `emits: File` gives (open the CSV in its default app).
actions:
  - { id: copy-summary, kind: composer, target: row, label: Copy summary, insert: "{{row.summary}}" }
  - { id: copy-columns, kind: composer, target: row, label: Copy columns, insert: "{{row.column_list}}" }
