# =runbook: a stateful checklist you tick off one step at a time.
#
# What this app teaches (copy the pattern):
# 1. A form (`inputs:`) picks the runbook and the owner; the script keeps progress in ONE small JSON file (~/.bolt/runbook-state.json, the same ~/.bolt folder =expense uses) and writes nothing else.
# 2. A `utility` action re-invokes this same app with a short command (`next`, `reset`), so a button press runs the script again and the pane redraws with the new state.
# 3. `=runbook demo` is a stateless half-finished sample, every row marked SAMPLE DATA; a damaged state file gets an honest error row and is never overwritten silently.
#
# Enter (Mark done) always marks the NEXT step done. Tab opens Copy status (a status update to paste into chat) and Reset.
# Reset takes two presses: the first shows what would be cleared and writes nothing; Reset on that row confirms.
# Starting a different runbook while one is unfinished is refused until you Reset, so progress is never lost silently.
schema_version: 1
runtime: bridge
id: runbook
chip: runbook
title: Runbook
icon: list-checks
description: "Onboarding, incident or release checklist with saved progress, a next-step pane and a chat status update. =runbook demo shows sample data"
placeholder_examples: ["Pick a runbook and press Start", "demo"]
emits: Generic

inputs:
  - { name: runbook, type: select, label: Runbook, default: "Onboard a new hire", options: ["Onboard a new hire", "Handle an incident", "Ship a release", "Sample (demo)"] }
  - { name: owner, type: text, label: Owner, placeholder: "Who runs this one", max_length: 40 }

submit:
  label: Start or resume

# The form values (runbook, owner) override these when the form is submitted.
# A utility action routes here with only a short command as the query.
args:
  - { name: cmd, from: "query.word(0)", default: "" }
  - { name: runbook, from: "query.word(1)", default: "" }
  - { name: owner, from: "query.word(2)", default: "" }

bridge:
  command:
    macos: "python3 {{scripts_dir}}/bolt-runbook.py {{cmd}} {{runbook}} {{owner}}"
    linux: "python3 {{scripts_dir}}/bolt-runbook.py {{cmd}} {{runbook}} {{owner}}"
    windows: "python {{scripts_dir}}/bolt-runbook.py {{cmd}} {{runbook}} {{owner}}"
  parse: json
  timeout_seconds: 5

presentation:
  widget: list
  title_field: title
  subtitle_field: subtitle
  searchable: true
  right_widget:
    kind: entity_preview
    mode: selected_row
    bind:
      title: "{{row.title}}"
      subtitle: "{{row.subtitle}}"
      fields:
        - { label: Runbook, value: "{{row.runbook}}" }
        - { label: Owner, value: "{{row.owner}}" }
        - { label: Progress, value: "{{row.progress}}" }
        - { label: Data, value: "{{row.data}}" }
      body: "{{row.body}}"
      actions: [next, copy-status, reset]

actions:
  - { id: next, kind: utility, target: row, label: Mark done, target_chip: runbook, query_template: "{{row.next_query}}", primary: true }
  - { id: copy-status, kind: composer, target: row, label: Copy status, insert: "{{row.status_text}}" }
  - { id: reset, kind: utility, target: row, label: Reset, target_chip: runbook, query_template: "{{row.reset_query}}" }
