# =pipeline <path-to-csv>: a sales pipeline from a CSV, with a funnel chart.
#
# What this app teaches (copy the pattern):
# 1. One right pane only, so the chart plots just the rows that carry the field it reads (`stage_total`); deal rows leave that field out and stay plain list rows with their own actions.
# 2. The script is read-only and refuses bad input in words: relative path, missing file, folder, binary, NUL byte, over 5 MB, bad numbers or dates (skipped rows are counted, never hidden).
# 3. `=pipeline demo` shows fabricated deals, every row marked SAMPLE DATA; with no path the list opens on a "Try with sample data" row, and a bad path never falls back to sample data.
#
# CSV columns: deal, stage, amount (required); owner, last_contact as YYYY-MM-DD (optional).
# Stale means no contact in 14 or more days on a deal that is not Won or Lost.
# Enter (Copy) copies a follow-up email draft on a deal row, and the one-line summary on a stage or summary row; Tab opens Copy summary.
# The whole query is passed as ONE argument, so a path with spaces works.
schema_version: 1
runtime: bridge
id: pipeline
chip: pipeline
title: Sales pipeline
icon: chart-column
description: "A sales pipeline from a CSV: funnel by stage, stale deals first, follow-up drafts. =pipeline demo shows sample data"
placeholder_examples: ["~/deals.csv", "demo"]
emits: Generic

dispatch:
  confirm_label: 'Read pipeline {{query}}'
  confirm_hint: "Press Enter to read the CSV (read-only) · a full path such as ~/deals.csv · demo shows sample data"

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

presentation:
  widget: list
  title_field: title
  subtitle_field: subtitle
  searchable: true
  right_widget:
    kind: chart
    mode: list_data
    bind:
      type: bar
      x: stage_label
      y: stage_total
      label: "Pipeline by stage (amount in $)"

actions:
  - { id: draft, kind: composer, target: row, label: Copy, insert: "{{row.primary_text}}", primary: true }
  - { id: copy-summary, kind: composer, target: row, label: Copy summary, insert: "{{row.summary}}" }
