name: data-pipeline-summarize
version: "1.0"
description: "Summarize an analysis report into an executive brief. Auto-triggered by data-pipeline-ingest."
tags: [pipeline, data, chain]

triggers:
  - on_kind: "analysis-report"
    on_tag: "ready"
    # source_name auto-mapped from entity metadata (matching key name)
    input_map:
      source_entity: "${trigger.entity_kref}"

inputs:
  - name: source_entity
    type: string
    required: true
    description: "Kref of the analysis report entity to summarize"
  - name: source_name
    type: string
    required: false
    default: "report"
    description: "Name of the source entity (auto-filled from entity metadata)"
  - name: original_task
    type: string
    required: false
    default: ""
    description: "Original ingestion task (auto-filled from entity metadata)"
  - name: cwd
    type: string
    required: false
    default: "~"

steps:
  - id: summarize
    name: "Generate executive summary"
    type: agent
    agent:
      agent_type: claude
      role: researcher
      prompt: |
        You have received an analysis report (entity: ${inputs.source_entity}, name: ${inputs.source_name}).

        Create a concise executive summary with:
        - Key findings (3-5 bullet points)
        - Critical metrics
        - Recommended actions
        - Risk assessment

        Keep it under 500 words, suitable for leadership review.
      timeout: 180

  - id: publish
    name: "Publish executive summary"
    type: output
    depends_on: [summarize]
    output:
      format: markdown
      template: "${summarize.output}"
      entity_name: "${inputs.source_name}-summary"
      entity_kind: "executive-summary"
      entity_tag: "ready"
      entity_metadata:
        source_name: "${inputs.source_name}-summary"
        original_task: "${inputs.original_task}"

outputs:
  - name: summary
    source: "${summarize.output}"
  - name: entity_kref
    source: "${publish.output_data.entity_kref}"
