# =posture: a read-only device check against a recommended baseline. Not an audit or a certification; results are
# evidence for this device only. Overview row: score, failing and not-measured chips, date, device, OS. Check rows come
# failing first and drill in place (row `nav`, Enter), every drilled view starts with a Back row. Each check shows its
# basis (Recommended baseline, Advisory or Informational), a one-sentence reason, the rule, expected and measured value,
# and the exact commands run with their output. NOT MEASURED is never a pass. Fix guidance is text to copy.
# Optional: a posture-mapping.json file in this user-utils folder adds a company policy reference and control ids per
# check (plain data, 64 KB at most, never executed). Without it the report says "No company mapping loaded".
# Overview footer: Copy (the plain-text report with its SHA-256), Copy JSON, Save report. Save report is a manifest action of
# kind `run`: ONE click on it runs this app once with the fixed query `save now` and writes the report, nothing is typed into the
# bar. It goes through the same invoke path as Enter on the app's confirm row (device approval, run log, one run at a time),
# and a script row can never carry a `run` action. The device adds a click marker ({{press}}, the action id) only for that
# button's press, never from the query, args or a row: typed or chained `save now` and plain `save` show the confirm step and
# write nothing. The save writes a self-contained HTML report and a JSON file as NEW files in Downloads (O_EXCL, never
# overwrites), then Bolt opens that HTML file in the default browser. The device names the files for a click ({{outname}}, posture-<random>) and opens only that exact name in the real Downloads folder; nothing this script prints is ever opened by Bolt. `emits: File` gives file behaviour (Enter opens, Tab offers Reveal in Finder) to a row that
# carries an absolute `path`; only the row shown after a save does. Every other row is unchanged.
schema_version: 1
runtime: bridge
id: posture
chip: posture
title: "Device compliance"
icon: shield-check
description: "Read-only device check against a recommended baseline, with evidence and a saved HTML report. Not an audit."
placeholder_examples: ["Enter for overview", "disk", "export"]
emits: File
args:
  - { name: view, from: "query.word(0)", default: overview }
  - { name: arg, from: "query.word(1)", default: "-" }
bridge:
  command:
    macos: "python3 {{scripts_dir}}/bolt-posture.py {{view}} {{arg}} {{press}} {{outname}}"
    linux: "python3 {{scripts_dir}}/bolt-posture.py {{view}} {{arg}} {{press}} {{outname}}"
    windows: "python {{scripts_dir}}/bolt-posture.py {{view}} {{arg}} {{press}} {{outname}}"
  parse: json
  timeout_seconds: 20
presentation:
  widget: list
  title_field: title
  subtitle_field: subtitle
  view_arg: view
  right_widget:
    kind: entity_preview
    mode: selected_row
    bind:
      title: "{{row.title}}"
      subtitle: "{{row.subtitle}}"
      tiles_above:
        title: "{{row.kpi_label}}"
        value: "{{row.kpi_value}}"
        unit: "{{row.kpi_unit}}"
        max: "{{row.kpi_max}}"
        subtitle: "{{row.kpi_note}}"
        badge: "{{row.kpi_badge}}"
      fields:
        - { label: "Checked", value: "{{row.o_date}}" }
        - { label: "Device", value: "{{row.o_model}}" }
        - { label: "System", value: "{{row.o_os}}" }
        - { label: "Failing", value: "{{row.o_fail}}", kind: chips }
        - { label: "Not measured", value: "{{row.o_unk}}", kind: chips }
        - { label: "Advisory", value: "{{row.o_adv}}", kind: chips }
        - { label: "Passing", value: "{{row.o_pass}}", kind: chips }
        - { label: "Mapping", value: "{{row.o_map}}" }
      body: "{{row.body}}"
      actions: [copy, save_report]
  views:
    overview: {}
    summary:
      right_widget:
        kind: entity_preview
        mode: selected_row
        bind:
          title: "{{row.title}}"
          subtitle: "{{row.subtitle}}"
          tiles_above:
            title: "{{row.kpi_label}}"
            value: "{{row.kpi_value}}"
            unit: "{{row.kpi_unit}}"
            max: "{{row.kpi_max}}"
            subtitle: "{{row.kpi_note}}"
            badge: "{{row.kpi_badge}}"
          fields:
            - { label: "Checked", value: "{{row.o_date}}" }
            - { label: "Device", value: "{{row.o_model}}" }
            - { label: "System", value: "{{row.o_os}}" }
            - { label: "Failing", value: "{{row.o_fail}}", kind: chips }
            - { label: "Not measured", value: "{{row.o_unk}}", kind: chips }
            - { label: "Advisory", value: "{{row.o_adv}}", kind: chips }
            - { label: "Passing", value: "{{row.o_pass}}", kind: chips }
            - { label: "Mapping", value: "{{row.o_map}}" }
          body: "{{row.body}}"
          actions: [copy, save_report]
    check:
      right_widget:
        kind: entity_preview
        mode: selected_row
        bind:
          title: "{{row.title}}"
          subtitle: "{{row.subtitle}}"
          fields:
            - { label: "Result", value: "{{row.r_result}}", kind: chips }
            - { label: "Expected", value: "{{row.r_expect}}" }
            - { label: "Measured", value: "{{row.r_seen}}" }
            - { label: "Basis", value: "{{row.r_basis}}" }
            - { label: "Why", value: "{{row.r_why}}" }
            - { label: "Company policy", value: "{{row.r_policy}}" }
            - { label: "Controls", value: "{{row.r_controls}}" }
            - { label: "Commands", value: "{{row.r_cmds}}" }
            - { label: "To fix", value: "{{row.r_fix}}" }
          body: "{{row.body}}"
          actions: [copy]
    export:
      right_widget:
        kind: entity_preview
        mode: selected_row
        bind:
          title: "{{row.title}}"
          subtitle: "{{row.subtitle}}"
          fields:
            - { label: "What", value: "{{row.x_what}}" }
            - { label: "SHA-256", value: "{{row.x_hash}}" }
          body: "{{row.body}}"
          actions: [copy]
    save:
      right_widget:
        kind: entity_preview
        mode: selected_row
        bind:
          title: "{{row.title}}"
          subtitle: "{{row.subtitle}}"
          fields:
            - { label: "What", value: "{{row.x_what}}" }
            - { label: "SHA-256", value: "{{row.x_hash}}" }
          body: "{{row.body}}"
          actions: [copy]
actions:
  - { id: copy, kind: composer, target: row, label: Copy, insert: "{{row.copy_text}}" }
  - { id: save_report, kind: run, label: Save report, icon: download, query_template: "save now" }
