apiVersion: ops.aiwg.io/v1
kind: OpsCapability
metadata:
  name: bt6-merge-train-flow
  labels:
    category: maintainer
    scope: cross-repository
  annotations:
    blast-radius: "repository-wide; merges one validated PR and may separately reconcile linked issues"
spec:
  description: Dry-run or execute an explicitly authorized BT6 merge train one verified PR at a time.
  version: "0.2.0"
  inputs:
    - name: pr_numbers
      type: list
      required: true
      description: Ordered candidates and audited head SHAs from a current queue audit.
    - name: method
      type: string
      required: false
      description: Merge method; must be permitted by authoritative project policy.
    - name: dry_run
      type: boolean
      required: false
      default: true
      description: Report the planned train without merging when true.
    - name: authorization
      type: object
      required: false
      description: Current operator authorization for repository, candidates, method, and live mutation.
  outputs:
    - name: authorization_record
      type: object
      description: Resolved target, actor, scope, method, mode, and authority evidence.
    - name: merged_prs
      type: list
      description: Merged PRs with exact SHA, method, checks, resulting commit, and linked-issue outcomes.
    - name: stopped_before
      type: list
      description: Skipped or blocked candidates with exact stop reason.
    - name: refreshed_queue
      type: list
      description: Base, CI, review, issue, dependency, and queue state after each merge or dry-run check.
  target_requirements:
    os: [linux, macos]
    capabilities: [git]
  agent: bt6-release-integrator
  idempotent: false
  steps:
    - name: confirm-context-and-authorization
      description: Require canonical repository/tracker resolution, current queue audit, expected actor, allowed method, and explicit live authorization.
    - name: verify-one-candidate
      description: Re-read exact head, base, mergeability, reviews, checks, dependencies, feedback, and risk-surface evidence.
    - name: confirm-provider-assessment
      description: For external-provider changes, require a current assessment with complete integration, claim traceability, and merge-ready exact-head gates.
    - name: merge-one
      description: Merge exactly one candidate only when dry_run is false and every gate passes.
    - name: verify-result
      description: Verify canonical-branch result and post-merge CI before any further action.
    - name: reconcile
      description: Observe linked-issue outcomes and mutate them only with separate explicit authorization.
    - name: refresh
      description: Refresh base, queue, checks, reviews, dependencies, and ordering before another candidate.
  verification:
    command: "git status --short --branch >/dev/null && git remote -v >/dev/null"
    expect: "command exits 0 and live report includes explicit authorization plus tracker-derived merge evidence"
