components:
    parameters:
        ApprovalID:
            in: path
            name: id
            required: true
            schema:
                type: string
        BundlePageLimit:
            in: query
            name: limit
            schema:
                default: 50
                maximum: 200
                minimum: 1
                type: integer
        Digest:
            in: path
            name: digest
            required: true
            schema:
                $ref: '#/components/schemas/Digest'
        ExecutionID:
            in: path
            name: id
            required: true
            schema:
                type: string
        IntentType:
            in: path
            name: type
            required: true
            schema:
                pattern: ^[a-z0-9_]+\.[a-z0-9_]+$
                type: string
        PrincipalID:
            in: path
            name: id
            required: true
            schema:
                pattern: ^[A-Za-z0-9:._@-]{1,128}$
                type: string
        StatsBucket:
            description: Hourly buckets cover at most 14 days.
            in: query
            name: bucket
            schema:
                default: day
                enum:
                    - hour
                    - day
                type: string
        StatsFormat:
            in: query
            name: format
            schema:
                default: json
                enum:
                    - json
                    - csv
                type: string
        StatsFrom:
            description: Start of the period, inclusive. Defaults to 7 days before `to`; at most 90 days.
            in: query
            name: from
            schema:
                format: date-time
                type: string
        StatsTo:
            description: End of the period, exclusive. Defaults to now.
            in: query
            name: to
            schema:
                format: date-time
                type: string
        StatsZone:
            description: IANA `Area/Location` time zone of the buckets, or UTC.
            in: query
            name: tz
            schema:
                default: UTC
                maxLength: 64
                type: string
    requestBodies:
        Note:
            content:
                application/json:
                    schema:
                        additionalProperties: false
                        properties:
                            note:
                                maxLength: 2000
                                type: string
                        required:
                            - note
                        type: object
            description: Empty, or a note.
    responses:
        Forbidden:
            content:
                application/problem+json:
                    schema:
                        $ref: '#/components/schemas/Problem'
            description: The principal is not human or lacks the role.
        Problem:
            content:
                application/problem+json:
                    schema:
                        $ref: '#/components/schemas/Problem'
            description: A problem.
        Refusal:
            content:
                application/problem+json:
                    schema:
                        $ref: '#/components/schemas/Problem'
            description: A refusal with a code (`APPROVAL_NOT_PENDING`, `HASH_MISMATCH`, `NOT_ELIGIBLE`, `INVALID_STATE`, `INVALID_OUTPUT`).
        Unauthenticated:
            content:
                application/problem+json:
                    schema:
                        $ref: '#/components/schemas/Problem'
            description: No valid token (with `WWW-Authenticate`).
        Uploaded:
            content:
                application/json:
                    schema:
                        properties:
                            digest:
                                $ref: '#/components/schemas/Digest'
                            warnings:
                                items:
                                    type: object
                                type: array
                        required:
                            - digest
                            - warnings
                        type: object
            description: Stored or stored already.
    schemas:
        ApprovalDecision:
            properties:
                approver:
                    type: string
                decided_at:
                    format: date-time
                    type: string
                decision:
                    enum:
                        - approve
                        - deny
                    type: string
                evidence_level:
                    enum:
                        - token
                        - oidc
                        - webauthn
                    type: string
            required:
                - approver
                - decision
                - evidence_level
                - decided_at
            type: object
        ApprovalDetail:
            properties:
                approval_id:
                    type: string
                decisions:
                    items:
                        properties:
                            approver:
                                type: string
                            decided_at:
                                format: date-time
                                type: string
                            decision:
                                type: string
                            evidence_level:
                                type: string
                        required:
                            - approver
                            - decision
                            - evidence_level
                            - decided_at
                        type: object
                    type: array
                execution_hash:
                    type: string
                execution_id:
                    type: string
                expires_at:
                    format: date-time
                    type: string
                rationale:
                    oneOf:
                        - type: "null"
                        - properties:
                            label:
                                type: string
                            text:
                                type: string
                          required:
                            - label
                            - text
                          type: object
                requester:
                    properties:
                        on_behalf_of:
                            type:
                                - string
                                - "null"
                        principal:
                            type: string
                    required:
                        - principal
                        - on_behalf_of
                    type: object
                requirements:
                    items:
                        properties:
                            distinct_from_requester:
                                type: boolean
                            min_evidence:
                                enum:
                                    - token
                                    - oidc
                                    - webauthn
                                type: string
                            role:
                                type: string
                            rules:
                                items:
                                    properties:
                                        message:
                                            type: string
                                        rule:
                                            type: string
                                    required:
                                        - rule
                                        - message
                                    type: object
                                type: array
                            satisfied:
                                type: boolean
                        required:
                            - role
                            - distinct_from_requester
                            - satisfied
                            - rules
                        type: object
                    type: array
                status:
                    type: string
                steps:
                    items:
                        properties:
                            id:
                                type: string
                            input:
                                description: The clear input for a human who meets a requirement by role and distinctness; the redacted audit copy for any other operator, admin or named role; null for a viewer or auditor, or when the copy is erased.
                            intent:
                                type: string
                            version:
                                type: integer
                        required:
                            - id
                            - intent
                            - version
                            - input
                        type: object
                    type: array
                summary:
                    items:
                        type: string
                    type: array
            required:
                - approval_id
                - execution_id
                - summary
                - steps
                - requirements
                - requester
                - rationale
                - expires_at
                - execution_hash
                - status
                - decisions
            type: object
        ApprovalItem:
            properties:
                approval_id:
                    type: string
                created_at:
                    format: date-time
                    type: string
                decided_at:
                    description: The decision that ended the approval (the deny, or the last approval); null for any other status.
                    format: date-time
                    type:
                        - string
                        - "null"
                deciders:
                    items:
                        $ref: '#/components/schemas/ApprovalDecision'
                    type: array
                execution_hash:
                    type: string
                execution_id:
                    type: string
                expires_at:
                    format: date-time
                    type: string
                requester:
                    properties:
                        on_behalf_of:
                            type:
                                - string
                                - "null"
                        principal:
                            type: string
                    required:
                        - principal
                        - on_behalf_of
                    type: object
                required:
                    description: The roles of the requirements still unsatisfied.
                    items:
                        type: string
                    type: array
                requirements:
                    items:
                        properties:
                            distinct_from_requester:
                                type: boolean
                            min_evidence:
                                enum:
                                    - token
                                    - oidc
                                    - webauthn
                                type: string
                            role:
                                type: string
                            satisfied:
                                type: boolean
                        required:
                            - role
                            - distinct_from_requester
                            - satisfied
                        type: object
                    type: array
                status:
                    enum:
                        - pending
                        - approved
                        - denied
                        - expired
                        - cancelled
                    type: string
                summary:
                    items:
                        type: string
                    type: array
                time_to_decision_seconds:
                    description: '`decided_at` minus `created_at`.'
                    type:
                        - number
                        - "null"
            required:
                - approval_id
                - execution_id
                - status
                - summary
                - required
                - requirements
                - requester
                - deciders
                - created_at
                - expires_at
                - decided_at
                - time_to_decision_seconds
                - execution_hash
            type: object
        ApprovalRule:
            description: A `require_approval` head written as constants. Its conditions decide which submissions it applies to, so it names no intents; `domain` is the package it is written in.
            properties:
                distinct_from_requester:
                    type: boolean
                domain:
                    type: string
                file:
                    type: string
                min_evidence:
                    type: string
                role:
                    type: string
                rule:
                    type: string
            required:
                - rule
                - role
                - file
                - domain
                - distinct_from_requester
            type: object
        AuditEvent:
            properties:
                actor:
                    type: string
                at:
                    format: date-time
                    type: string
                body:
                    additionalProperties: true
                    description: The event's body as stored; payloads appear as hashes.
                    type: object
                execution_id:
                    type:
                        - string
                        - "null"
                hash:
                    type: string
                prev_hash:
                    type: string
                seq:
                    type: integer
                step_index:
                    type:
                        - integer
                        - "null"
                type:
                    type: string
            required:
                - seq
                - at
                - type
                - execution_id
                - step_index
                - actor
                - body
                - prev_hash
                - hash
            type: object
        AuditHead:
            properties:
                at:
                    format: date-time
                    type:
                        - string
                        - "null"
                hash:
                    type: string
                seq:
                    type: integer
            required:
                - seq
                - hash
                - at
            type: object
        Bundle:
            properties:
                activated_at:
                    description: The latest activation; null if never.
                    format: date-time
                    type:
                        - string
                        - "null"
                activated_by:
                    type:
                        - string
                        - "null"
                active:
                    type: boolean
                digest:
                    $ref: '#/components/schemas/Digest'
                size:
                    description: Bytes of the stored archive.
                    type: integer
                uploaded_at:
                    format: date-time
                    type: string
            required:
                - digest
                - uploaded_at
                - size
                - active
                - activated_at
                - activated_by
            type: object
        BundleActivation:
            properties:
                actor:
                    type: string
                at:
                    format: date-time
                    type: string
                channel:
                    enum:
                        - api
                        - console
                        - null
                    type:
                        - string
                        - "null"
                digest:
                    $ref: '#/components/schemas/Digest'
                note:
                    type:
                        - string
                        - "null"
                previous:
                    description: The digest it replaced; null for the first, and on older events that did not record it.
                    type:
                        - string
                        - "null"
                seq:
                    type: integer
            required:
                - seq
                - at
                - digest
                - previous
                - actor
                - note
                - channel
            type: object
        BundleDetail:
            allOf:
                - $ref: '#/components/schemas/Bundle'
                - properties:
                    catalogue:
                        oneOf:
                            - type: "null"
                            - properties:
                                approval_rules:
                                    items:
                                        $ref: '#/components/schemas/ApprovalRule'
                                    type: array
                                approval_rules_computed:
                                    description: require_approval heads not written as constants, which cannot be attributed to a role.
                                    type: integer
                                approval_rules_truncated:
                                    description: The bundle holds more than the 500 approval rules listed.
                                    type: boolean
                                connectors:
                                    items:
                                        properties:
                                            auth:
                                                oneOf:
                                                    - type: "null"
                                                    - properties:
                                                        client_id:
                                                            type: string
                                                        header:
                                                            type: string
                                                        scope:
                                                            type: string
                                                        secret:
                                                            description: The secret's name in sefra.yaml, never its value.
                                                            type: string
                                                        secret_prefixes:
                                                            items:
                                                                type: string
                                                            type: array
                                                        token_url:
                                                            type: string
                                                        type:
                                                            type: string
                                                      required:
                                                        - type
                                                        - secret
                                                      type: object
                                            base_url:
                                                type: string
                                            body_encoding:
                                                enum:
                                                    - json
                                                    - form
                                                type: string
                                            fail_closed_on:
                                                additionalProperties: true
                                                description: Response values that make an answer untrusted.
                                                type:
                                                    - object
                                                    - "null"
                                            max_concurrency:
                                                type: integer
                                            name:
                                                type: string
                                            timeout_ms:
                                                type: integer
                                            type:
                                                type: string
                                            used_by:
                                                items:
                                                    type: string
                                                maxItems: 100
                                                type: array
                                            used_by_truncated:
                                                type: boolean
                                        required:
                                            - name
                                            - type
                                            - base_url
                                            - auth
                                            - timeout_ms
                                            - max_concurrency
                                            - body_encoding
                                            - fail_closed_on
                                            - used_by
                                            - used_by_truncated
                                        type: object
                                    type: array
                                coverage:
                                    description: Percent of policy lines the tests cover.
                                    type:
                                        - number
                                        - "null"
                                grants:
                                    items:
                                        allOf:
                                            - $ref: '#/components/schemas/GrantSubject'
                                            - properties:
                                                intents:
                                                    description: The patterns as written.
                                                    items:
                                                        type: string
                                                    maxItems: 100
                                                    type: array
                                                resolved:
                                                    description: The intent types they match.
                                                    items:
                                                        type: string
                                                    maxItems: 100
                                                    type: array
                                                resolved_truncated:
                                                    type: boolean
                                              required:
                                                - intents
                                                - resolved
                                                - resolved_truncated
                                              type: object
                                    type: array
                                grants_truncated:
                                    description: The bundle holds more than the 500 grants listed.
                                    type: boolean
                                intents:
                                    items:
                                        $ref: '#/components/schemas/IntentSummary'
                                    maxItems: 500
                                    type: array
                                intents_truncated:
                                    type: boolean
                                limits:
                                    properties:
                                        default:
                                            oneOf:
                                                - type: "null"
                                                - $ref: '#/components/schemas/Rate'
                                        intents:
                                            additionalProperties:
                                                $ref: '#/components/schemas/Rate'
                                            type: object
                                        principals:
                                            additionalProperties:
                                                $ref: '#/components/schemas/Rate'
                                            type: object
                                    required:
                                        - default
                                        - principals
                                        - intents
                                    type: object
                                policies:
                                    items:
                                        properties:
                                            file:
                                                type: string
                                            tests:
                                                items:
                                                    properties:
                                                        line:
                                                            type: integer
                                                        name:
                                                            type: string
                                                        pass:
                                                            type: boolean
                                                    required:
                                                        - name
                                                        - line
                                                        - pass
                                                    type: object
                                                type: array
                                        required:
                                            - file
                                            - tests
                                        type: object
                                    type: array
                              required:
                                - intents
                                - intents_truncated
                                - grants_truncated
                                - policies
                                - coverage
                                - grants
                                - limits
                                - connectors
                                - approval_rules
                                - approval_rules_truncated
                                - approval_rules_computed
                              type: object
                    catalogue_error:
                        type:
                            - string
                            - "null"
                    files:
                        items:
                            $ref: '#/components/schemas/BundleFile'
                        type: array
                    files_truncated:
                        type: boolean
                  required:
                    - files
                    - files_truncated
                    - catalogue
                    - catalogue_error
                  type: object
        BundleFile:
            properties:
                kind:
                    enum:
                        - text
                        - binary
                        - too_large
                    type: string
                path:
                    type: string
                sha256:
                    pattern: ^[0-9a-f]{64}$
                    type: string
                size:
                    type: integer
            required:
                - path
                - sha256
                - size
                - kind
            type: object
        BundleIntent:
            allOf:
                - $ref: '#/components/schemas/IntentSummary'
                - properties:
                    compensate:
                        oneOf:
                            - type: "null"
                            - $ref: '#/components/schemas/BundleOperation'
                    execute:
                        oneOf:
                            - type: "null"
                            - $ref: '#/components/schemas/BundleOperation'
                    facts:
                        items:
                            properties:
                                connector:
                                    type: string
                                method:
                                    type: string
                                name:
                                    type: string
                                path:
                                    type: string
                                response_schema:
                                    additionalProperties: true
                                    type:
                                        - object
                                        - "null"
                                sensitive:
                                    items:
                                        type: string
                                    type: array
                                timeout_ms:
                                    type: integer
                            required:
                                - name
                                - connector
                                - method
                                - path
                                - timeout_ms
                                - sensitive
                                - response_schema
                            type: object
                        type: array
                    file:
                        type: string
                    input_schema:
                        additionalProperties: true
                        type:
                            - object
                            - "null"
                    output_schema:
                        additionalProperties: true
                        type:
                            - object
                            - "null"
                    probe:
                        oneOf:
                            - type: "null"
                            - properties:
                                absent_when:
                                    items:
                                        type: integer
                                    type: array
                                applied_when:
                                    items:
                                        type: integer
                                    type: array
                                connector:
                                    type: string
                                method:
                                    type: string
                                output:
                                    additionalProperties: true
                                    type:
                                        - object
                                        - "null"
                                path:
                                    type: string
                              required:
                                - connector
                                - method
                                - path
                                - applied_when
                                - absent_when
                                - output
                              type: object
                    summary_template:
                        type: string
                  required:
                    - file
                    - input_schema
                    - output_schema
                    - facts
                    - execute
                    - compensate
                    - probe
                    - summary_template
                  type: object
        BundleOperation:
            properties:
                already_undone:
                    items:
                        type: integer
                    type: array
                body:
                    description: The body template as written.
                connector:
                    type: string
                idempotency:
                    oneOf:
                        - type: "null"
                        - properties:
                            header:
                                type: string
                            mode:
                                enum:
                                    - header
                                    - natural
                                    - none
                                type: string
                          required:
                            - mode
                          type: object
                method:
                    type: string
                output:
                    additionalProperties: true
                    type:
                        - object
                        - "null"
                path:
                    type: string
                success:
                    items:
                        type: integer
                    type: array
                success_when:
                    additionalProperties: true
                    description: On compensate only. JSON pointers and the values a success answer's body must hold for the undo to count as done.
                    type: object
            required:
                - connector
                - method
                - path
                - body
                - idempotency
                - success
                - already_undone
                - output
            type: object
        Connector:
            properties:
                auth_type:
                    type:
                        - string
                        - "null"
                base_url:
                    type: string
                facts:
                    items:
                        properties:
                            intent:
                                type: string
                            name:
                                type: string
                        required:
                            - intent
                            - name
                        type: object
                    type: array
                facts_truncated:
                    type: boolean
                intents:
                    items:
                        type: string
                    type: array
                intents_truncated:
                    type: boolean
                max_concurrency:
                    type: integer
                name:
                    type: string
                secret:
                    properties:
                        name:
                            description: The secret's name in connectors.yaml.
                            type: string
                        state:
                            enum:
                                - resolves
                                - unresolved
                                - not_configured
                            type: string
                    required:
                        - name
                        - state
                    type:
                        - object
                        - "null"
                steps:
                    additionalProperties:
                        type: integer
                    description: Steps by status.
                    type: object
                steps_total:
                    type: integer
                timeout_ms:
                    type: integer
                type:
                    type: string
            required:
                - name
                - type
                - base_url
                - auth_type
                - secret
                - timeout_ms
                - max_concurrency
                - intents
                - intents_truncated
                - facts
                - facts_truncated
                - steps
                - steps_total
            type: object
        ConnectorList:
            properties:
                bundle:
                    $ref: '#/components/schemas/Digest'
                connectors:
                    items:
                        $ref: '#/components/schemas/Connector'
                    type: array
                from:
                    format: date-time
                    type: string
                to:
                    format: date-time
                    type: string
                unattributed_steps:
                    additionalProperties:
                        type: integer
                    type: object
            required:
                - from
                - to
                - bundle
                - connectors
                - unattributed_steps
            type: object
        Control:
            properties:
                note:
                    type:
                        - string
                        - "null"
                set_at:
                    format: date-time
                    type: string
                set_by:
                    description: A principal id, or `sefra` for the denial breaker.
                    type: string
                source:
                    enum:
                        - operator
                        - breaker
                    type: string
                subject:
                    description: The intent type or principal id; absent for the pause.
                    type: string
            required:
                - set_by
                - set_at
                - note
                - source
            type: object
        Digest:
            pattern: ^sha256:[0-9a-f]{64}$
            type: string
        ExecutionDetail:
            properties:
                approval:
                    properties:
                        approval_id:
                            type: string
                        expires_at:
                            format: date-time
                            type: string
                        status:
                            type: string
                    required:
                        - approval_id
                        - status
                        - expires_at
                    type: object
                bundle_digest:
                    type: string
                created_at:
                    format: date-time
                    type: string
                error:
                    oneOf:
                        - $ref: '#/components/schemas/ExecutionError'
                        - type: "null"
                execution_hash:
                    type: string
                execution_id:
                    type: string
                finished_at:
                    format: date-time
                    type:
                        - string
                        - "null"
                on_behalf_of:
                    description: The user the agent acted for, as recorded at acceptance, or null.
                principal:
                    type: string
                principal_roles:
                    description: As recorded at acceptance.
                    items:
                        type: string
                    type: array
                principal_type:
                    description: As recorded at acceptance.
                    enum:
                        - agent
                        - human
                    type: string
                status:
                    $ref: '#/components/schemas/ExecutionStatus'
                steps:
                    items:
                        properties:
                            compensation_attempts:
                                type: integer
                            forward_attempts:
                                type: integer
                            input_hash:
                                description: The hash of the redacted input in the audit payload table.
                                type:
                                    - string
                                    - "null"
                            intent:
                                type: string
                            intent_version:
                                type: integer
                            output_hash:
                                description: The hash of the redacted output.
                                type:
                                    - string
                                    - "null"
                            status:
                                $ref: '#/components/schemas/StepStatus'
                            step_id:
                                type: string
                        required:
                            - step_id
                            - intent
                            - intent_version
                            - status
                            - forward_attempts
                            - compensation_attempts
                            - input_hash
                            - output_hash
                        type: object
                    type: array
                updated_at:
                    format: date-time
                    type: string
                workflow_started:
                    type: boolean
            required:
                - execution_id
                - status
                - error
                - principal
                - principal_type
                - principal_roles
                - on_behalf_of
                - bundle_digest
                - execution_hash
                - workflow_started
                - created_at
                - updated_at
                - finished_at
                - steps
            type: object
        ExecutionError:
            properties:
                code:
                    type: string
                message:
                    type: string
                retryable:
                    type: boolean
                stage:
                    type: string
                step:
                    type: string
                violations:
                    items:
                        properties:
                            actual: {}
                            hint:
                                type: string
                            limit: {}
                            message:
                                type: string
                            path:
                                type: string
                            rule:
                                type: string
                        required:
                            - message
                        type: object
                    type: array
            required:
                - code
                - stage
                - message
                - retryable
            type: object
        ExecutionStatus:
            enum:
                - pending_approval
                - executing
                - compensating
                - succeeded
                - rejected
                - failed
                - rolled_back
                - needs_intervention
                - resolved_manually
            type: string
        ExecutionSummary:
            properties:
                attention:
                    description: Why an execution in needs_intervention waits; null for any other status.
                    oneOf:
                        - type: "null"
                        - properties:
                            reason:
                                enum:
                                    - step_unknown
                                    - compensation_failed
                                type: string
                            step:
                                description: The step id.
                                type: string
                          required:
                            - reason
                            - step
                          type: object
                bundle_digest:
                    type: string
                created_at:
                    description: Received.
                    format: date-time
                    type: string
                error_code:
                    type:
                        - string
                        - "null"
                execution_id:
                    type: string
                finished_at:
                    format: date-time
                    type:
                        - string
                        - "null"
                intents:
                    description: The steps' intent types in step order; empty without steps.
                    items:
                        type: string
                    type: array
                on_behalf_of:
                    description: The user's id, as recorded at acceptance.
                    type:
                        - string
                        - "null"
                principal:
                    type: string
                status:
                    $ref: '#/components/schemas/ExecutionStatus'
                updated_at:
                    format: date-time
                    type: string
            required:
                - execution_id
                - status
                - principal
                - on_behalf_of
                - intents
                - error_code
                - bundle_digest
                - created_at
                - updated_at
                - finished_at
                - attention
            type: object
        GrantSubject:
            description: A role or a principal id; exactly one is set.
            properties:
                principal:
                    type: string
                role:
                    type: string
            type: object
        IntentSummary:
            properties:
                connectors:
                    items:
                        type: string
                    type: array
                description:
                    type: string
                disabled:
                    description: The intent's control now, not bundle content.
                    type: boolean
                effect:
                    enum:
                        - read
                        - write
                    type: string
                granted_to:
                    items:
                        $ref: '#/components/schemas/GrantSubject'
                    maxItems: 50
                    type: array
                granted_to_truncated:
                    type: boolean
                irreversible:
                    type: boolean
                tags:
                    items:
                        type: string
                    type: array
                type:
                    type: string
                version:
                    type: integer
            required:
                - type
                - version
                - description
                - effect
                - irreversible
                - tags
                - connectors
                - granted_to
                - granted_to_truncated
                - disabled
            type: object
        LicenseStatus:
            properties:
                clock_regression:
                    description: The clock is more than 24 hours behind the latest time in the audit trail.
                    type: boolean
                days_left:
                    description: Whole days until `expires_at`; negative after it.
                    type:
                        - integer
                        - "null"
                deployment_id:
                    format: uuid
                    type: string
                development_build:
                    description: Not a release build. Its evaluation never ends and it trusts the development key.
                    type: boolean
                effect:
                    enum:
                        - freeze
                        - stop
                    type: string
                expires_at:
                    description: The licence's expiry or the evaluation's end; null when there is no end.
                    format: date-time
                    type:
                        - string
                        - "null"
                file:
                    properties:
                        configured:
                            description: '`SEFRA_LICENSE_FILE` is set.'
                            type: boolean
                        license_id:
                            description: The licence the file holds, when it verified.
                            type: string
                        problem:
                            description: Why the file was ignored.
                            type: string
                    required:
                        - configured
                    type: object
                first_event_hash:
                    description: The hash of the audit trail's first event; empty while the trail is.
                    type: string
                frozen:
                    description: A bundle never active on this deployment is not activated.
                    type: boolean
                lapses_at:
                    description: 'When the lapse takes effect: the expiry plus the grace days.'
                    format: date-time
                    type:
                        - string
                        - "null"
                license:
                    description: The installed licence with the latest `issued_at`; null in evaluation.
                    properties:
                        customer:
                            type: string
                        expires_at:
                            format: date-time
                            type: string
                        grace_days:
                            type: integer
                        issued_at:
                            format: date-time
                            type: string
                        kind:
                            enum:
                                - trial
                                - pilot
                                - subscription
                                - nonproduction
                            type: string
                        license_id:
                            type: string
                        not_before:
                            format: date-time
                            type: string
                        tier:
                            type: string
                    required:
                        - license_id
                        - customer
                        - kind
                        - issued_at
                        - not_before
                        - expires_at
                        - grace_days
                    type:
                        - object
                        - "null"
                limits:
                    properties:
                        governed_per_month:
                            description: The volume band. It is reported and never enforced; null is no band.
                            type:
                                - integer
                                - "null"
                        systems_of_record:
                            description: The most systems of record a newly activated bundle may name; null is no limit.
                            type:
                                - integer
                                - "null"
                    required:
                        - systems_of_record
                        - governed_per_month
                    type: object
                phase:
                    enum:
                        - unknown
                        - evaluation
                        - valid
                        - expiring
                        - grace
                        - lapsed
                    type: string
                read_error:
                    description: Set when the licence could not be read just now. The rest is the last state that was read, which still applies; `phase` is `unknown` if none was.
                    type: string
                stopped:
                    description: New submissions are refused.
                    type: boolean
                usage:
                    properties:
                        governed:
                            description: Executions accepted in that month.
                            type: integer
                        month:
                            description: The current UTC month as YYYY-MM.
                            type: string
                        systems_of_record:
                            description: Distinct hosts of the active bundle's connectors; null with no bundle loaded.
                            type:
                                - integer
                                - "null"
                    required:
                        - month
                        - governed
                        - systems_of_record
                    type: object
                version:
                    type: string
            required:
                - deployment_id
                - version
                - first_event_hash
                - development_build
                - phase
                - stopped
                - frozen
                - expires_at
                - lapses_at
                - days_left
                - license
                - limits
                - usage
                - file
                - clock_regression
            type: object
        Notification:
            properties:
                alert_id:
                    type: string
                approval_id:
                    type: string
                at:
                    format: date-time
                    type: string
                attempt:
                    type: integer
                channel:
                    type: string
                error:
                    description: What failed without a status; never a URL or credential.
                    type:
                        - string
                        - "null"
                execution_id:
                    type:
                        - string
                        - "null"
                kind:
                    enum:
                        - approval
                        - alert
                    type: string
                outcome:
                    enum:
                        - delivered
                        - failed
                    type: string
                seq:
                    type: integer
                status:
                    description: HTTP status of a failed attempt.
                    type:
                        - integer
                        - "null"
            required:
                - seq
                - at
                - kind
                - outcome
                - channel
                - attempt
                - execution_id
                - status
                - error
            type: object
        Payload:
            properties:
                body:
                    description: The redacted body as stored, or null when erased.
                erased:
                    type: boolean
                hash:
                    type: string
            required:
                - hash
                - erased
                - body
            type: object
        Principal:
            properties:
                access:
                    oneOf:
                        - $ref: '#/components/schemas/PrincipalAccess'
                        - type: "null"
                bundle:
                    type:
                        - string
                        - "null"
                decisions:
                    additionalProperties:
                        format: int64
                        type: integer
                    type: object
                executions:
                    $ref: '#/components/schemas/PrincipalStatusCounts'
                first_activity:
                    format: date-time
                    type: string
                from:
                    format: date-time
                    type: string
                id:
                    type: string
                last_activity:
                    format: date-time
                    type: string
                on_behalf_of:
                    $ref: '#/components/schemas/PrincipalStatusCounts'
                operator_actions:
                    additionalProperties:
                        format: int64
                        type: integer
                    type: object
                refusals:
                    format: int64
                    type: integer
                refusals_by_code:
                    additionalProperties:
                        format: int64
                        type: integer
                    type: object
                relations:
                    items:
                        $ref: '#/components/schemas/PrincipalRelation'
                    type: array
                roles:
                    items:
                        type: string
                    type:
                        - array
                        - "null"
                roles_at:
                    format: date-time
                    type:
                        - string
                        - "null"
                roles_source:
                    enum:
                        - execution
                        - on_behalf_of
                        - approval_decision
                        - null
                    type:
                        - string
                        - "null"
                suspension:
                    oneOf:
                        - $ref: '#/components/schemas/PrincipalSuspension'
                        - type: "null"
                to:
                    format: date-time
                    type: string
            required:
                - id
                - relations
                - roles
                - roles_source
                - roles_at
                - first_activity
                - last_activity
                - suspension
                - from
                - to
                - executions
                - on_behalf_of
                - refusals
                - refusals_by_code
                - decisions
                - operator_actions
                - bundle
                - access
            type: object
        PrincipalAccess:
            properties:
                intent_limits:
                    additionalProperties:
                        $ref: '#/components/schemas/PrincipalRate'
                    type: object
                intents:
                    items:
                        type: string
                    type: array
                intents_truncated:
                    type: boolean
                limit:
                    oneOf:
                        - $ref: '#/components/schemas/PrincipalRate'
                        - type: "null"
                limit_source:
                    enum:
                        - principal
                        - default
                        - ""
                    type: string
            required:
                - intents
                - intents_truncated
                - limit
                - limit_source
                - intent_limits
            type: object
        PrincipalList:
            properties:
                from:
                    format: date-time
                    type: string
                next_after:
                    type: string
                principals:
                    items:
                        $ref: '#/components/schemas/PrincipalRow'
                    type: array
                to:
                    format: date-time
                    type: string
            required:
                - from
                - to
                - principals
            type: object
        PrincipalRate:
            properties:
                burst:
                    type: integer
                per_minute:
                    type: integer
            required:
                - per_minute
                - burst
            type: object
        PrincipalRelation:
            enum:
                - agent
                - submitter
                - user
                - approver
                - operator
            type: string
        PrincipalRow:
            properties:
                decisions:
                    format: int64
                    type: integer
                executions:
                    format: int64
                    type: integer
                first_activity:
                    format: date-time
                    type: string
                id:
                    type: string
                last_activity:
                    format: date-time
                    type: string
                operator_actions:
                    format: int64
                    type: integer
                refusals:
                    format: int64
                    type: integer
                relations:
                    items:
                        $ref: '#/components/schemas/PrincipalRelation'
                    type: array
                roles:
                    description: As last seen; null when no record holds them, as for a person seen only as an operator.
                    items:
                        type: string
                    type:
                        - array
                        - "null"
                roles_at:
                    format: date-time
                    type:
                        - string
                        - "null"
                roles_source:
                    enum:
                        - execution
                        - on_behalf_of
                        - approval_decision
                        - null
                    type:
                        - string
                        - "null"
                suspension:
                    oneOf:
                        - $ref: '#/components/schemas/PrincipalSuspension'
                        - type: "null"
            required:
                - id
                - relations
                - roles
                - roles_source
                - roles_at
                - first_activity
                - last_activity
                - suspension
                - executions
                - refusals
                - decisions
                - operator_actions
            type: object
        PrincipalStatusCounts:
            properties:
                by_status:
                    additionalProperties:
                        format: int64
                        type: integer
                    type: object
                total:
                    format: int64
                    type: integer
            required:
                - total
                - by_status
            type: object
        PrincipalSuspension:
            properties:
                note:
                    type:
                        - string
                        - "null"
                set_at:
                    format: date-time
                    type: string
                set_by:
                    type: string
                source:
                    enum:
                        - operator
                        - breaker
                    type: string
            required:
                - set_by
                - set_at
                - note
                - source
            type: object
        Problem:
            properties:
                code:
                    type: string
                detail:
                    type: string
                status:
                    type: integer
                title:
                    type: string
                type:
                    description: '`about:blank`.'
                    type: string
            required:
                - type
                - title
                - status
            type: object
        Rate:
            properties:
                burst:
                    type: integer
                per_minute:
                    type: integer
            required:
                - per_minute
                - burst
            type: object
        Refusal:
            properties:
                at:
                    format: date-time
                    type: string
                code:
                    type: string
                count:
                    type: integer
                execution_id:
                    type:
                        - string
                        - "null"
                intents:
                    items:
                        type: string
                    type: array
                kind:
                    enum:
                        - rejected
                        - admission
                        - admission_summary
                    type: string
                principal:
                    type: string
                rules:
                    items:
                        type: string
                    type: array
                seq:
                    type: integer
                stage:
                    enum:
                        - admission
                        - validation
                        - policy
                    type: string
            required:
                - seq
                - at
                - kind
                - principal
                - code
                - stage
                - count
                - execution_id
                - intents
                - rules
            type: object
        RefusalSummary:
            properties:
                by_agent:
                    items:
                        properties:
                            breaker:
                                properties:
                                    counted:
                                        description: The breaker's own count now.
                                        type: integer
                                    distance:
                                        description: Refusals left before the breaker suspends; 0 at or past it.
                                        type: integer
                                    suspended:
                                        type: boolean
                                    threshold:
                                        type: integer
                                    window_s:
                                        type: integer
                                required:
                                    - counted
                                    - threshold
                                    - window_s
                                    - distance
                                    - suspended
                                type: object
                            principal:
                                type: string
                            refusals:
                                type: integer
                        required:
                            - principal
                            - refusals
                            - breaker
                        type: object
                    type: array
                by_code:
                    items:
                        properties:
                            code:
                                type: string
                            refusals:
                                type: integer
                            stage:
                                enum:
                                    - admission
                                    - validation
                                    - policy
                                type: string
                        required:
                            - code
                            - stage
                            - refusals
                        type: object
                    type: array
                by_rule:
                    items:
                        properties:
                            codes:
                                items:
                                    type: string
                                type: array
                            refusals:
                                type: integer
                            rule:
                                type:
                                    - string
                                    - "null"
                        required:
                            - rule
                            - codes
                            - refusals
                        type: object
                    type: array
                from:
                    format: date-time
                    type: string
                to:
                    format: date-time
                    type: string
                total:
                    type: integer
            required:
                - from
                - to
                - total
                - by_code
                - by_rule
                - by_agent
            type: object
        Replay:
            properties:
                changed:
                    items:
                        $ref: '#/components/schemas/ReplayChange'
                    type: array
                cut:
                    properties:
                        decisions:
                            type: boolean
                        period:
                            type: boolean
                    required:
                        - period
                        - decisions
                    type: object
                decisions:
                    description: Decisions read in the period, at most 5000.
                    type: integer
                digest:
                    $ref: '#/components/schemas/Digest'
                first_seq:
                    type:
                        - integer
                        - "null"
                from:
                    description: The start actually replayed, after the period bound.
                    format: date-time
                    type: string
                last_seq:
                    type:
                        - integer
                        - "null"
                not_replayed:
                    description: Sequence numbers of decisions that could not be replayed.
                    items:
                        type: integer
                    type: array
                output_only:
                    description: Decisions whose output changed with the same effect.
                    type: integer
                to:
                    format: date-time
                    type: string
            required:
                - digest
                - from
                - to
                - first_seq
                - last_seq
                - decisions
                - output_only
                - cut
                - changed
                - not_replayed
            type: object
        ReplayChange:
            properties:
                at:
                    format: date-time
                    type: string
                execution_id:
                    type:
                        - string
                        - "null"
                intent:
                    type: string
                phase:
                    type: string
                recorded:
                    $ref: '#/components/schemas/ReplaySide'
                replayed:
                    $ref: '#/components/schemas/ReplaySide'
                seq:
                    type: integer
                step_index:
                    type:
                        - integer
                        - "null"
            required:
                - seq
                - at
                - execution_id
                - step_index
                - phase
                - intent
                - recorded
                - replayed
            type: object
        ReplaySide:
            properties:
                effect:
                    enum:
                        - allow
                        - deny
                        - require_approval
                        - error
                    type: string
                rules:
                    items:
                        type: string
                    type: array
            required:
                - effect
                - rules
            type: object
        SelfCheck:
            properties:
                broken:
                    oneOf:
                        - properties:
                            reason:
                                type: string
                            seq:
                                type: integer
                          required:
                            - seq
                            - reason
                          type: object
                        - type: "null"
                checked_at:
                    format: date-time
                    type: string
                duration_ms:
                    type: integer
                from:
                    type: integer
                head:
                    description: The head of the check's snapshot, also when the chain is broken.
                    properties:
                        hash:
                            type: string
                        seq:
                            type: integer
                    required:
                        - seq
                        - hash
                    type: object
                ok:
                    type: boolean
                to:
                    description: Below `from` for an empty chain.
                    type: integer
            required:
                - checked_at
                - duration_ms
                - from
                - to
                - head
                - ok
                - broken
            type: object
        StatsSeries:
            description: One series of Insights. `rows` hold scalars in the order of `columns`; a chart, its table and its CSV read the same rows.
            properties:
                bucket:
                    enum:
                        - hour
                        - day
                        - null
                    type:
                        - string
                        - "null"
                columns:
                    items:
                        type: string
                    type: array
                from:
                    format: date-time
                    type: string
                rows:
                    items:
                        items:
                            type:
                                - string
                                - number
                                - "null"
                        type: array
                    type: array
                series:
                    type: string
                to:
                    format: date-time
                    type: string
                tz:
                    description: The zone of the buckets; UTC for `governed`; null for a series without buckets.
                    type:
                        - string
                        - "null"
            required:
                - series
                - from
                - to
                - tz
                - bucket
                - columns
                - rows
            type: object
        StatsSummary:
            properties:
                attention:
                    properties:
                        approvals_pending:
                            type: integer
                        breaker_suspensions:
                            type: integer
                        failed_notifications:
                            type: integer
                        failed_since:
                            format: date-time
                            type: string
                        nearest_expiry:
                            format: date-time
                            type:
                                - string
                                - "null"
                        needs_intervention:
                            type: integer
                        not_started:
                            type: integer
                        not_started_after_s:
                            type: integer
                    required:
                        - needs_intervention
                        - approvals_pending
                        - nearest_expiry
                        - not_started
                        - not_started_after_s
                        - breaker_suspensions
                        - failed_notifications
                        - failed_since
                    type: object
                executions:
                    properties:
                        by_status:
                            additionalProperties:
                                type: integer
                            type: object
                        total:
                            type: integer
                    required:
                        - by_status
                        - total
                    type: object
                from:
                    format: date-time
                    type: string
                governed:
                    properties:
                        count:
                            type: integer
                        month:
                            description: YYYY-MM, UTC.
                            type: string
                    required:
                        - month
                        - count
                    type: object
                to:
                    format: date-time
                    type: string
            required:
                - from
                - to
                - executions
                - governed
                - attention
            type: object
        StepStatus:
            enum:
                - pending
                - executing
                - succeeded
                - failed
                - unknown
                - compensating
                - compensated
                - compensation_failed
                - skipped
            type: string
        System:
            properties:
                bundle:
                    oneOf:
                        - properties:
                            activated_at:
                                format: date-time
                                type:
                                    - string
                                    - "null"
                            activated_by:
                                type:
                                    - string
                                    - "null"
                            digest:
                                $ref: '#/components/schemas/Digest'
                            loaded:
                                type: boolean
                          required:
                            - digest
                            - loaded
                            - activated_at
                            - activated_by
                          type: object
                        - type: "null"
                checks:
                    items:
                        properties:
                            name:
                                type: string
                            ok:
                                type: boolean
                        required:
                            - name
                            - ok
                        type: object
                    type: array
                configuration:
                    additionalProperties: true
                    type: object
                in_flight:
                    properties:
                        by_status:
                            additionalProperties:
                                type: integer
                            type: object
                        executions:
                            type: integer
                    required:
                        - executions
                        - by_status
                    type: object
                open_workflows:
                    oneOf:
                        - properties:
                            count:
                                type: integer
                            more:
                                type: boolean
                          required:
                            - count
                            - more
                          type: object
                        - type: "null"
                ready:
                    type: boolean
                roles:
                    items:
                        enum:
                            - api
                            - worker
                        type: string
                    type: array
                secrets:
                    items:
                        properties:
                            name:
                                type: string
                            ok:
                                type: boolean
                            source:
                                description: 'Where the value comes from: environment variable, file or secret manager path.'
                                type: string
                        required:
                            - name
                            - source
                            - ok
                        type: object
                    type: array
                version:
                    type: string
            required:
                - version
                - roles
                - ready
                - checks
                - secrets
                - bundle
                - in_flight
                - open_workflows
                - configuration
            type: object
    securitySchemes:
        bearer:
            description: An OAuth access token of the operator resource.
            scheme: bearer
            type: http
info:
    description: 'Every route needs an OAuth access token of a human principal, unless it says otherwise. Roles build on each other: `sefra_viewer`, `sefra_auditor`, `sefra_operator`, `sefra_admin`. Any role an approval requirement names may also decide that approval. Errors are problem documents (RFC 9457), and refusals carry a `code`.'
    license:
        name: Proprietary
    summary: Decide approvals, operate executions, read the audit trail and manage bundles.
    title: Sefra operator API
    version: "1"
openapi: 3.1.0
paths:
    /healthz:
        get:
            operationId: healthz
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                properties:
                                    status:
                                        const: ok
                                required:
                                    - status
                                type: object
                    description: The process is up.
            security: []
            tags:
                - probes
    /readyz:
        get:
            operationId: readyz
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                properties:
                                    status:
                                        const: ready
                                required:
                                    - status
                                type: object
                    description: Ready.
                "503":
                    $ref: '#/components/responses/Problem'
            security: []
            tags:
                - probes
    /v1/approvals:
        get:
            description: '`status=pending` is the inbox: the live pending approvals the caller may decide, nearest expiry first, then by id. A page may be short with `next` set, since rows the caller may not decide are dropped after the read. Any other status, or `all`, is the history, newest first: every approval for `sefra_viewer` and above, otherwise those whose requirements name one of the caller''s roles. `summary` is empty unless the caller holds `sefra_auditor` or above or a role the approval names. Unknown or repeated parameters are 400.'
            operationId: listApprovals
            parameters:
                - in: query
                  name: status
                  schema:
                    default: pending
                    enum:
                        - pending
                        - approved
                        - denied
                        - expired
                        - cancelled
                        - all
                    type: string
                - description: '`history` with `status=pending` lists every pending approval in the history''s scope, newest first; `inbox` goes with `status=pending` only.'
                  in: query
                  name: view
                  schema:
                    enum:
                        - inbox
                        - history
                    type: string
                - description: The `next` of the previous page. An inbox cursor that names no approval is 400.
                  in: query
                  name: after
                  schema:
                    type: string
                - in: query
                  name: limit
                  schema:
                    default: 50
                    maximum: 200
                    minimum: 1
                    type: integer
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                properties:
                                    approvals:
                                        items:
                                            $ref: '#/components/schemas/ApprovalItem'
                                        type: array
                                    next:
                                        description: The `after` of the next page; absent on the last.
                                        type: string
                                required:
                                    - approvals
                                type: object
                    description: A page.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
            summary: The inbox (pending, what the caller may decide) or the history of approvals, paged.
            tags:
                - approvals
    /v1/approvals/{id}:
        get:
            description: 'Readable by a person whose role it names and by `sefra_viewer` and above. A person whose role it names sees everything it may: the clear `input` only if that person could decide the approval, by role and `distinct_from_requester`, and otherwise the redacted audit copy. For anyone else, `summary` and `rationale` need `sefra_auditor` or above (else `[]` and `null`), and each step''s redacted `input` needs `sefra_operator` or `sefra_admin` (else `null`).'
            operationId: getApproval
            parameters:
                - $ref: '#/components/parameters/ApprovalID'
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/ApprovalDetail'
                    description: The approval.
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
                "404":
                    $ref: '#/components/responses/Problem'
            summary: One approval.
            tags:
                - approvals
    /v1/approvals/{id}/decisions:
        post:
            description: Any authenticated principal; the rules answer an agent with `NOT_ELIGIBLE`.
            operationId: decideApproval
            parameters:
                - $ref: '#/components/parameters/ApprovalID'
            requestBody:
                content:
                    application/json:
                        schema:
                            additionalProperties: false
                            properties:
                                comment:
                                    type: string
                                decision:
                                    enum:
                                        - approve
                                        - deny
                                    type: string
                                execution_hash:
                                    type: string
                            required:
                                - decision
                                - execution_hash
                            type: object
                required: true
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                properties:
                                    approval_id:
                                        type: string
                                    execution_id:
                                        type: string
                                    status:
                                        type: string
                                required:
                                    - approval_id
                                    - execution_id
                                    - status
                                type: object
                    description: Recorded.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Refusal'
                "404":
                    $ref: '#/components/responses/Problem'
                "409":
                    $ref: '#/components/responses/Refusal'
            security:
                - bearer: []
            summary: Record a decision at evidence level token.
            tags:
                - approvals
    /v1/audit/check:
        get:
            description: The worker recomputes the whole chain every `every_s` seconds. This is the service's check of its own record; the independent check is `sefra audit verify` against the database.
            operationId: getAuditCheck
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                properties:
                                    every_s:
                                        type: integer
                                    last:
                                        oneOf:
                                            - $ref: '#/components/schemas/SelfCheck'
                                            - type: "null"
                                    last_failure:
                                        oneOf:
                                            - $ref: '#/components/schemas/SelfCheck'
                                            - type: "null"
                                    stale:
                                        description: 'The last result is older than three intervals: the self-check has stopped running and the result is not current.'
                                        type: boolean
                                required:
                                    - every_s
                                    - last
                                    - last_failure
                                    - stale
                                type: object
                    description: The results, null before the first.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
            summary: The last self-check of the chain and the last failed one. `sefra_viewer` and above.
            tags:
                - audit
    /v1/audit/events:
        get:
            description: '`after_seq` alone pages in ascending order, 100 events, `next_after_seq` on a full page. Each parameter is given once; any other parameter is refused. `to` needs `from`. Ascending pages with `after_seq`, descending (`order=desc`) with `before_seq`; a cursor of the other order is refused.'
            operationId: listAuditEvents
            parameters:
                - description: An event type, or up to 20 comma-separated.
                  in: query
                  name: type
                  schema:
                    type: string
                - description: A principal id or `system`.
                  in: query
                  name: actor
                  schema:
                    type: string
                - in: query
                  name: execution
                  schema:
                    type: string
                - description: On `at`, inclusive.
                  in: query
                  name: from
                  schema:
                    format: date-time
                    type: string
                - description: On `at`, exclusive.
                  in: query
                  name: to
                  schema:
                    format: date-time
                    type: string
                - description: Inclusive.
                  in: query
                  name: from_seq
                  schema:
                    minimum: 1
                    type: integer
                - description: Inclusive.
                  in: query
                  name: to_seq
                  schema:
                    minimum: 1
                    type: integer
                - in: query
                  name: order
                  schema:
                    default: asc
                    enum:
                        - asc
                        - desc
                    type: string
                - in: query
                  name: after_seq
                  schema:
                    default: 0
                    minimum: 0
                    type: integer
                - description: The `next_before_seq` of the previous page.
                  in: query
                  name: before_seq
                  schema:
                    minimum: 1
                    type: integer
                - in: query
                  name: limit
                  schema:
                    default: 100
                    maximum: 500
                    minimum: 1
                    type: integer
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                properties:
                                    events:
                                        items:
                                            $ref: '#/components/schemas/AuditEvent'
                                        type: array
                                    next_after_seq:
                                        description: Ascending; present when the page is full.
                                        type: integer
                                    next_before_seq:
                                        description: Descending; present when the page is full.
                                        type: integer
                                required:
                                    - events
                                type: object
                    description: A page.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
            summary: The trail, filtered, in sequence order or newest first, a page at a time. `sefra_viewer` and above; without `read_payloads`, policy-authored text and computed rule names are withheld from `body`.
            tags:
                - audit
    /v1/audit/export:
        get:
            description: Sequence numbers; `from` defaults to 1, `to` to the head, and a `to` past the head is the head. At most 100,000 events per request. The range is fixed in one snapshot, then an `audit.exported` event (range, reader, channel) is written, then the file is streamed; if the event cannot be written nothing is sent. An error while streaming aborts the response, and each write must be accepted within 30 s. At most two exports run at once per process (503 with `Retry-After` beyond). Check the file with `sefra audit verify --file`; its last hash is `Sefra-Last-Hash`, and equals `Sefra-Head-Hash` when `to` is the head.
            operationId: exportAudit
            parameters:
                - in: query
                  name: from
                  schema:
                    default: 1
                    minimum: 1
                    type: integer
                - in: query
                  name: to
                  schema:
                    minimum: 1
                    type: integer
            responses:
                "200":
                    content:
                        application/x-ndjson:
                            schema:
                                description: One event per line.
                                type: string
                    description: The file.
                    headers:
                        Content-Disposition:
                            description: '`attachment; filename="sefra-audit-F-T.jsonl"`'
                            schema:
                                type: string
                        Sefra-Head-Hash:
                            schema:
                                type: string
                        Sefra-Head-Seq:
                            description: The head of the snapshot.
                            schema:
                                type: integer
                        Sefra-Last-Hash:
                            description: The hash of event T.
                            schema:
                                type: string
                        Sefra-Range:
                            description: '`F-T`, the range exported.'
                            schema:
                                type: string
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
                "500":
                    $ref: '#/components/responses/Problem'
                "503":
                    $ref: '#/components/responses/Problem'
            summary: Events `from` to `to` as the JSON Lines file of `sefra audit export`. `sefra_auditor` and above.
            tags:
                - audit
    /v1/audit/head:
        get:
            operationId: getAuditHead
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/AuditHead'
                    description: The head; `at` is null for an empty chain.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
            summary: The chain head, the document `sefra audit head` prints. `sefra_viewer` and above.
            tags:
                - audit
    /v1/audit/payloads/{hash}:
        get:
            description: 'Sensitive values appear as `{"$redacted": "<keyed hash>"}`. A body deleted or past its retention is `erased`, its hash still in the chain; no stored row is 404 with problem type `urn:sefra:problem:payload-not-stored` (any other 404 is not about the hash). Every read is written to the structured log with the reader''s principal.'
            operationId: getAuditPayload
            parameters:
                - in: path
                  name: hash
                  required: true
                  schema:
                    pattern: ^(sha256:)?[0-9a-f]{64}$
                    type: string
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/Payload'
                    description: The body, or erased.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
                "404":
                    $ref: '#/components/responses/Problem'
            summary: A payload body by hash, redacted as stored. `sefra_auditor` and above, any hash.
            tags:
                - audit
    /v1/bundles:
        get:
            operationId: listBundles
            parameters:
                - description: Continue after this bundle of the previous page.
                  in: query
                  name: before
                  schema:
                    $ref: '#/components/schemas/Digest'
                - $ref: '#/components/parameters/BundlePageLimit'
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                properties:
                                    bundles:
                                        items:
                                            $ref: '#/components/schemas/Bundle'
                                        type: array
                                    next_before:
                                        $ref: '#/components/schemas/Digest'
                                required:
                                    - bundles
                                type: object
                    description: A page of bundles; `next_before` on a full page.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
            summary: Every stored bundle, newest upload first. `sefra_viewer` and above.
            tags:
                - bundles
        post:
            operationId: uploadBundle
            requestBody:
                content:
                    application/gzip:
                        schema:
                            contentEncoding: binary
                            maxLength: 8388608
                            type: string
                required: true
            responses:
                "200":
                    $ref: '#/components/responses/Uploaded'
                "201":
                    $ref: '#/components/responses/Uploaded'
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
                "413":
                    $ref: '#/components/responses/Problem'
                "422":
                    content:
                        application/problem+json:
                            schema:
                                allOf:
                                    - $ref: '#/components/schemas/Problem'
                                    - properties:
                                        errors:
                                            items:
                                                properties:
                                                    file:
                                                        type: string
                                                    message:
                                                        type: string
                                                    path:
                                                        type: string
                                                required:
                                                    - file
                                                    - message
                                                type: object
                                            type: array
                                      required:
                                        - errors
                                      type: object
                    description: The bundle is invalid and was not stored.
            summary: Upload a gzip-compressed tar of a bundle directory; validated and stored, not activated.
            tags:
                - bundles
    /v1/bundles/{digest}:
        get:
            description: '`files` are in path order, at most 1,000 (`files_truncated` beyond); the bundle''s digest is computed over their paths and hashes. Content that does not have the digest is 409 and not shown; a read that runs out of time is 503 and says nothing about the bundle. The catalogue is bounded (500 intents, 500 grants, 50 subjects per intent, 100 types per grant), each with a `*_truncated` flag. It is parsed by the registry''s loader; a stored bundle that no longer loads has `catalogue: null` and `catalogue_error`. Connectors name their secret, never its value.'
            operationId: getBundle
            parameters:
                - $ref: '#/components/parameters/Digest'
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/BundleDetail'
                    description: The bundle.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
                "404":
                    $ref: '#/components/responses/Problem'
                "409":
                    $ref: '#/components/responses/Problem'
                "503":
                    $ref: '#/components/responses/Problem'
            summary: One stored bundle, its files with their hashes and its catalogue. `sefra_viewer` and above.
            tags:
                - bundles
    /v1/bundles/{digest}/activate:
        post:
            description: 'The console''s form requires a note; the API does not. A digest already active answers `activated: false` and writes nothing. A digest that was never active on this deployment is checked against the licence: 403 with `code` `LICENSE_EXPIRED` when the licence or the evaluation period has lapsed, and `LICENSE_LIMIT` when the bundle''s connectors name more systems of record than the licence allows. Each refusal is recorded as `bundle.activation_refused`. A digest that was active before is always activated.'
            operationId: activateBundle
            parameters:
                - $ref: '#/components/parameters/Digest'
            requestBody:
                $ref: '#/components/requestBodies/Note'
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                properties:
                                    activated:
                                        description: False if it was active already.
                                        type: boolean
                                    digest:
                                        type: string
                                required:
                                    - digest
                                    - activated
                                type: object
                    description: Active.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
                "404":
                    $ref: '#/components/responses/Problem'
            summary: Make a stored bundle the active one; also the roll-back to an earlier digest. `sefra_admin`.
            tags:
                - bundles
    /v1/bundles/{digest}/files/{path}:
        get:
            description: '`path` is the file''s path in the bundle, slashes included (`intents/procurement.get_budget.yaml`). `text` is the content for `kind: text` (valid UTF-8 without NUL, at most 1 MiB) and null for `binary` and `too_large`, which the console lists by hash.'
            operationId: getBundleFile
            parameters:
                - $ref: '#/components/parameters/Digest'
                - in: path
                  name: path
                  required: true
                  schema:
                    type: string
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                allOf:
                                    - $ref: '#/components/schemas/BundleFile'
                                    - properties:
                                        text:
                                            type:
                                                - string
                                                - "null"
                                      required:
                                        - text
                                      type: object
                    description: The file.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
                "404":
                    $ref: '#/components/responses/Problem'
                "409":
                    $ref: '#/components/responses/Problem'
                "503":
                    $ref: '#/components/responses/Problem'
            summary: One file of a stored bundle, as text when it may be shown. `sefra_viewer` and above.
            tags:
                - bundles
    /v1/bundles/{digest}/intents/{type}:
        get:
            operationId: getBundleIntent
            parameters:
                - $ref: '#/components/parameters/Digest'
                - $ref: '#/components/parameters/IntentType'
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/BundleIntent'
                    description: The intent as the manifest writes it, templates and all.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
                "404":
                    $ref: '#/components/responses/Problem'
                "409":
                    $ref: '#/components/responses/Problem'
                "503":
                    $ref: '#/components/responses/Problem'
            summary: The intent page of one intent type of a stored bundle. `sefra_viewer` and above.
            tags:
                - bundles
    /v1/bundles/activations:
        get:
            operationId: listBundleActivations
            parameters:
                - description: Continue after this event of the previous page.
                  in: query
                  name: before_seq
                  schema:
                    minimum: 1
                    type: integer
                - $ref: '#/components/parameters/BundlePageLimit'
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                properties:
                                    activations:
                                        items:
                                            $ref: '#/components/schemas/BundleActivation'
                                        type: array
                                    next_before_seq:
                                        type: integer
                                required:
                                    - activations
                                type: object
                    description: A page of activations; `next_before_seq` on a full page.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
            summary: The `bundle.activated` events, newest first. `sefra_viewer` and above.
            tags:
                - bundles
    /v1/bundles/active:
        get:
            operationId: getActiveBundle
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                properties:
                                    digest:
                                        $ref: '#/components/schemas/Digest'
                                    loaded:
                                        type: boolean
                                required:
                                    - digest
                                    - loaded
                                type: object
                    description: The active bundle.
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
                "404":
                    $ref: '#/components/responses/Problem'
            summary: The active digest, and whether this process has it loaded. `sefra_viewer` and above.
            tags:
                - bundles
    /v1/connectors:
        get:
            description: A step counts for the connector of its intent's `execute` operation in the active bundle, among the steps of executions accepted in `[from, to)`; other steps are in `unattributed_steps`. The range defaults to the last 7 days and is at most 31. A secret appears by name and state, never by value or source.
            operationId: listConnectors
            parameters:
                - in: query
                  name: from
                  schema:
                    format: date-time
                    type: string
                - in: query
                  name: to
                  schema:
                    format: date-time
                    type: string
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/ConnectorList'
                    description: The connectors.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
                "503":
                    content:
                        application/problem+json:
                            schema:
                                $ref: '#/components/schemas/Problem'
                    description: No bundle is active.
            summary: The systems of record of the active bundle, their secret state and steps by status. `sefra_viewer` and above.
            tags:
                - system
    /v1/controls:
        get:
            description: Setter, time and an operator's note from the `controls` row; `source` from the latest `operator.action` that set the control (`breaker` when its actor is `system`), whose note is the breaker's. Newest first, at most 1000 of each kind; `truncated` when a kind had more. No parameters.
            operationId: listControls
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                properties:
                                    disabled_intents:
                                        items:
                                            $ref: '#/components/schemas/Control'
                                        type: array
                                    paused:
                                        oneOf:
                                            - $ref: '#/components/schemas/Control'
                                            - type: "null"
                                    suspended_principals:
                                        items:
                                            $ref: '#/components/schemas/Control'
                                        type: array
                                    truncated:
                                        type: boolean
                                required:
                                    - paused
                                    - disabled_intents
                                    - suspended_principals
                                    - truncated
                                type: object
                    description: The controls.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
            summary: The active controls, who set each, and whether the denial breaker did. `sefra_viewer` and above.
            tags:
                - controls
    /v1/executions:
        get:
            description: 'Newest first by id (ids are time-sortable), or oldest first with `order=oldest`. Filters are combined with AND, each given at most once; each reads a value recorded at acceptance or refusal. A time range is at most 31 days: `from` without `to` runs to now, `to` without `from` is refused. A malformed, repeated, unknown or unbounded filter is 400. Indexes per filter: migration 0014.'
            operationId: listExecutions
            parameters:
                - description: Comma-separated execution statuses, or `in_flight`.
                  in: query
                  name: status
                  schema:
                    type: string
                - description: The authenticated principal (`executions.principal_id`).
                  in: query
                  name: principal
                  schema:
                    pattern: ^[A-Za-z0-9:._@-]{1,128}$
                    type: string
                - description: The user the agent acted for (`on_behalf_of.id`).
                  in: query
                  name: on_behalf_of
                  schema:
                    pattern: ^[A-Za-z0-9:._@-]{1,128}$
                    type: string
                - description: An intent type of any of the execution's steps. A refusal with `UNKNOWN_INTENT` has no step.
                  in: query
                  name: intent
                  schema:
                    pattern: ^[a-z0-9_]+\.[a-z0-9_]+$
                    type: string
                - description: The execution's error code.
                  in: query
                  name: code
                  schema:
                    pattern: ^[A-Z][A-Z_]{0,63}$
                    type: string
                - description: The bundle digest the execution was accepted or refused under.
                  in: query
                  name: bundle
                  schema:
                    $ref: '#/components/schemas/Digest'
                - description: Received at or after (RFC 3339).
                  in: query
                  name: from
                  schema:
                    format: date-time
                    type: string
                - description: Received before (RFC 3339); needs `from`; at most 31 days after it.
                  in: query
                  name: to
                  schema:
                    format: date-time
                    type: string
                - description: Accepted executions (`executing`, `pending_approval`) whose workflow has not started, received at least this many seconds ago in database time.
                  in: query
                  name: not_started_for
                  schema:
                    maximum: 86400
                    minimum: 0
                    type: integer
                - description: The `next` of the previous page; the list continues in its order.
                  in: query
                  name: after
                  schema:
                    type: string
                - in: query
                  name: order
                  schema:
                    default: newest
                    enum:
                        - newest
                        - oldest
                    type: string
                - in: query
                  name: limit
                  schema:
                    default: 100
                    maximum: 1000
                    minimum: 1
                    type: integer
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                properties:
                                    executions:
                                        items:
                                            $ref: '#/components/schemas/ExecutionSummary'
                                        type: array
                                    next:
                                        description: The `after` of the next page; absent on the last.
                                        type: string
                                required:
                                    - executions
                                type: object
                    description: A page.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
            summary: Executions newest first, filtered, paged. `sefra_viewer` and above.
            tags:
                - executions
    /v1/executions/{id}:
        get:
            operationId: getExecution
            parameters:
                - $ref: '#/components/parameters/ExecutionID'
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/ExecutionDetail'
                    description: The execution.
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
                "404":
                    $ref: '#/components/responses/Problem'
            summary: One execution without step bodies. `sefra_viewer` and above.
            tags:
                - executions
    /v1/executions/{id}/audit:
        get:
            operationId: getExecutionAudit
            parameters:
                - $ref: '#/components/parameters/ExecutionID'
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                properties:
                                    events:
                                        items:
                                            $ref: '#/components/schemas/AuditEvent'
                                        type: array
                                required:
                                    - events
                                type: object
                    description: The events.
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
                "404":
                    $ref: '#/components/responses/Problem'
            summary: Every audit event of one execution, in order. `sefra_viewer` and above; without `read_payloads`, policy-authored text and computed rule names are withheld from `body`.
            tags:
                - audit
    /v1/executions/{id}/cancel:
        post:
            operationId: cancelExecution
            parameters:
                - $ref: '#/components/parameters/ExecutionID'
            responses:
                "204":
                    description: Cancelled.
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
                "404":
                    $ref: '#/components/responses/Problem'
                "409":
                    $ref: '#/components/responses/Refusal'
            summary: Cancel an execution pending approval. `sefra_operator`, `sefra_admin`.
            tags:
                - executions
    /v1/executions/{id}/resolve:
        post:
            operationId: resolveExecution
            parameters:
                - $ref: '#/components/parameters/ExecutionID'
            requestBody:
                $ref: '#/components/requestBodies/Note'
            responses:
                "204":
                    description: Resolved.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
                "404":
                    $ref: '#/components/responses/Problem'
                "409":
                    $ref: '#/components/responses/Refusal'
            summary: Close an execution as resolved manually. `sefra_operator`, `sefra_admin`.
            tags:
                - executions
    /v1/executions/{id}/retry-compensation:
        post:
            operationId: retryCompensation
            parameters:
                - $ref: '#/components/parameters/ExecutionID'
            requestBody:
                $ref: '#/components/requestBodies/Note'
            responses:
                "204":
                    description: Retried.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
                "404":
                    $ref: '#/components/responses/Problem'
                "409":
                    $ref: '#/components/responses/Refusal'
            summary: Retry an exhausted compensation. `sefra_operator`, `sefra_admin`.
            tags:
                - executions
    /v1/executions/{id}/settle-step:
        post:
            operationId: settleStep
            parameters:
                - $ref: '#/components/parameters/ExecutionID'
            requestBody:
                content:
                    application/json:
                        schema:
                            additionalProperties: false
                            properties:
                                note:
                                    maxLength: 2000
                                    type: string
                                outcome:
                                    enum:
                                        - succeeded
                                        - failed
                                    type: string
                                output:
                                    type: object
                                step:
                                    type: string
                            required:
                                - step
                                - outcome
                            type: object
                required: true
            responses:
                "204":
                    description: Settled.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
                "404":
                    $ref: '#/components/responses/Problem'
                "409":
                    $ref: '#/components/responses/Refusal'
                "422":
                    $ref: '#/components/responses/Refusal'
            summary: Settle a step whose outcome is unknown. `sefra_operator`, `sefra_admin`.
            tags:
                - executions
    /v1/intents/{type}/disable:
        post:
            operationId: disableIntent
            parameters:
                - $ref: '#/components/parameters/IntentType'
            requestBody:
                $ref: '#/components/requestBodies/Note'
            responses:
                "204":
                    description: The control is in the requested state; operator.action is recorded.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
            summary: Disable an intent type. `sefra_operator`, `sefra_admin`.
            tags:
                - controls
    /v1/intents/{type}/enable:
        post:
            operationId: enableIntent
            parameters:
                - $ref: '#/components/parameters/IntentType'
            requestBody:
                $ref: '#/components/requestBodies/Note'
            responses:
                "204":
                    description: The control is in the requested state; operator.action is recorded.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
            summary: Enable an intent type again. `sefra_operator`, `sefra_admin`.
            tags:
                - controls
    /v1/license:
        get:
            description: 'Reads the licence file again before it answers. `phase` is `evaluation` while no licence was ever installed, then `valid`, `expiring` (inside the warning period), `grace` (expired, the lapse not yet in effect) or `lapsed`; `unknown` only until the first read. `effect` is what the lapse does on this deployment: `freeze` (a bundle never active here is not activated) or `stop` (the freeze, and new submissions are refused with `LICENSE_EXPIRED`). A deployment that has ever installed a `subscription` or `nonproduction` licence only freezes. `file.problem` says why the file at `SEFRA_LICENSE_FILE` was ignored; the installed licence then still applies. No parameters.'
            operationId: getLicense
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/LicenseStatus'
                    description: The licence state.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
            summary: The deployment's licence, its limits and what a lapse does. `sefra_viewer` and above.
            tags:
                - system
    /v1/notifications:
        get:
            description: From the `approval.notified`, `approval.notify_failed`, `alert.notified` and `alert.notify_failed` events. The range defaults to the last 24 hours and is at most 31 days; `to` needs `from`. `counts` covers the range whatever the other filters.
            operationId: listNotifications
            parameters:
                - in: query
                  name: kind
                  schema:
                    enum:
                        - approval
                        - alert
                    type: string
                - in: query
                  name: outcome
                  schema:
                    enum:
                        - delivered
                        - failed
                    type: string
                - in: query
                  name: channel
                  schema:
                    enum:
                        - webhook
                    type: string
                - in: query
                  name: from
                  schema:
                    format: date-time
                    type: string
                - in: query
                  name: to
                  schema:
                    format: date-time
                    type: string
                - description: The `next_before_seq` of the previous page.
                  in: query
                  name: before_seq
                  schema:
                    minimum: 1
                    type: integer
                - in: query
                  name: limit
                  schema:
                    default: 50
                    maximum: 200
                    minimum: 1
                    type: integer
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                properties:
                                    counts:
                                        items:
                                            properties:
                                                channel:
                                                    type: string
                                                delivered:
                                                    type: integer
                                                failed:
                                                    type: integer
                                                kind:
                                                    enum:
                                                        - approval
                                                        - alert
                                                    type: string
                                            required:
                                                - kind
                                                - channel
                                                - delivered
                                                - failed
                                            type: object
                                        type: array
                                    from:
                                        format: date-time
                                        type: string
                                    next_before_seq:
                                        description: Absent on the last page.
                                        type: integer
                                    notifications:
                                        items:
                                            $ref: '#/components/schemas/Notification'
                                        type: array
                                    to:
                                        format: date-time
                                        type: string
                                required:
                                    - from
                                    - to
                                    - notifications
                                    - counts
                                type: object
                    description: A page.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
            summary: Delivery attempts of approval.requested and operator.alert, newest first, paged. `sefra_viewer` and above.
            tags:
                - system
    /v1/pause:
        post:
            operationId: pause
            requestBody:
                $ref: '#/components/requestBodies/Note'
            responses:
                "204":
                    description: The control is in the requested state; operator.action is recorded.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
            summary: Pause admission. `sefra_operator`, `sefra_admin`.
            tags:
                - controls
    /v1/principals:
        get:
            description: Derived by query from executions, approval decisions and audit events; Sefra has no user store. Sorted by id, paged by `after`. Counts cover `[from, to)`, by default the last 30 days and at most 90; first and last activity are all time.
            operationId: listPrincipals
            parameters:
                - in: query
                  name: type
                  schema:
                    enum:
                        - agent
                        - person
                    type: string
                - in: query
                  name: role
                  schema:
                    maxLength: 128
                    type: string
                - in: query
                  name: after
                  schema:
                    maxLength: 512
                    type: string
                - in: query
                  name: limit
                  schema:
                    default: 50
                    maximum: 200
                    minimum: 1
                    type: integer
                - in: query
                  name: from
                  schema:
                    format: date-time
                    type: string
                - in: query
                  name: to
                  schema:
                    format: date-time
                    type: string
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/PrincipalList'
                    description: One page of principals.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
                "503":
                    content:
                        application/problem+json:
                            schema:
                                $ref: '#/components/schemas/Problem'
                    description: The read did not finish in time. Carries `Retry-After`.
                    headers:
                        Retry-After:
                            schema:
                                type: integer
            summary: Agents and people as Sefra has seen them. `sefra_viewer` and above.
            tags:
                - principals
    /v1/principals/{id}:
        get:
            description: '`access` is what the active bundle gives an id that submitted executions, under the roles of its newest one: the intents `tools/list` shows it and the limits admission applies. It is null for anyone else, whose roles for grants are unknown, and without an active bundle.'
            operationId: getPrincipal
            parameters:
                - description: Any subject an identity provider gave; wider than the grammar of a suspend.
                  in: path
                  name: id
                  required: true
                  schema:
                    maxLength: 512
                    minLength: 1
                    type: string
                - in: query
                  name: from
                  schema:
                    format: date-time
                    type: string
                - in: query
                  name: to
                  schema:
                    format: date-time
                    type: string
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/Principal'
                    description: The principal.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
                "404":
                    content:
                        application/problem+json:
                            schema:
                                $ref: '#/components/schemas/Problem'
                    description: Sefra has not seen this principal.
                "503":
                    content:
                        application/problem+json:
                            schema:
                                $ref: '#/components/schemas/Problem'
                    description: The read did not finish in time. Carries `Retry-After`.
                    headers:
                        Retry-After:
                            schema:
                                type: integer
            summary: One principal as seen, with every relation it has. `sefra_viewer` and above.
            tags:
                - principals
    /v1/principals/{id}/suspend:
        post:
            operationId: suspendPrincipal
            parameters:
                - $ref: '#/components/parameters/PrincipalID'
            requestBody:
                $ref: '#/components/requestBodies/Note'
            responses:
                "204":
                    description: The control is in the requested state; operator.action is recorded.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
            summary: Suspend a principal. `sefra_operator`, `sefra_admin`.
            tags:
                - controls
    /v1/principals/{id}/unsuspend:
        post:
            operationId: unsuspendPrincipal
            parameters:
                - $ref: '#/components/parameters/PrincipalID'
            requestBody:
                $ref: '#/components/requestBodies/Note'
            responses:
                "204":
                    description: The control is in the requested state; operator.action is recorded.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
            summary: Lift a suspension. `sefra_operator`, `sefra_admin`.
            tags:
                - controls
    /v1/refusals:
        get:
            description: From `execution.rejected` (kind `rejected`, one refused submission), `admission.refused` (kind `admission`, the first refusal of a principal and code in a minute) and `admission.refused_summary` (kind `admission_summary`, the window's count, which includes its first refusal). Admission refusals are counted, not recorded singly; they have stage `admission` and no execution, intents or rules, so `intent` and `rule` select only refused submissions. The range defaults to the last 24 hours and is at most 31 days.
            operationId: listRefusals
            parameters:
                - in: query
                  name: agent
                  schema:
                    type: string
                - in: query
                  name: code
                  schema:
                    type: string
                - in: query
                  name: stage
                  schema:
                    enum:
                        - admission
                        - validation
                        - policy
                    type: string
                - in: query
                  name: intent
                  schema:
                    type: string
                - in: query
                  name: rule
                  schema:
                    type: string
                - in: query
                  name: from
                  schema:
                    format: date-time
                    type: string
                - in: query
                  name: to
                  schema:
                    format: date-time
                    type: string
                - in: query
                  name: before_seq
                  schema:
                    minimum: 1
                    type: integer
                - in: query
                  name: limit
                  schema:
                    default: 50
                    maximum: 200
                    minimum: 1
                    type: integer
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                properties:
                                    from:
                                        format: date-time
                                        type: string
                                    next_before_seq:
                                        description: Absent on the last page.
                                        type: integer
                                    refusals:
                                        items:
                                            $ref: '#/components/schemas/Refusal'
                                        type: array
                                    to:
                                        format: date-time
                                        type: string
                                required:
                                    - from
                                    - to
                                    - refusals
                                type: object
                    description: A page.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
            summary: Refusals, newest first, paged. `sefra_viewer` and above.
            tags:
                - refusals
    /v1/refusals/summary:
        get:
            description: 'A refused submission counts one; an admission window one for `admission.refused` and `count - 1` for its summary. `by_rule` covers refused submissions only; `rule: null` is those whose violations name no policy rule. `by_agent` (at most 50) carries each agent''s state against the denial breaker now, not of the range. The range defaults to the last 24 hours and is at most 31 days.'
            operationId: getRefusalSummary
            parameters:
                - in: query
                  name: from
                  schema:
                    format: date-time
                    type: string
                - in: query
                  name: to
                  schema:
                    format: date-time
                    type: string
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/RefusalSummary'
                    description: The counts.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
            summary: Refusals of a range by code, by rule and by agent. `sefra_viewer` and above.
            tags:
                - refusals
    /v1/replays:
        post:
            description: Reads one read-only snapshot, verifies the audit chain and re-evaluates the recorded inputs under the candidate. It writes no event and no row. The period defaults to the 7 days before `to`, and `to` to now. A period over 31 days keeps its newest 31 days, and more than 5,000 decisions the newest 5,000; `cut` says which applied. The answer holds effects and rule names only, never a policy's output, messages or error text, which can quote a value a viewer may not read. A rule name that is not a string literal of the policy that produced it is shown as `(computed)`, since a computed name can quote a value too. A decision whose input is erased or past its retention is listed in `not_replayed`.
            operationId: replayCandidate
            requestBody:
                content:
                    application/json:
                        schema:
                            additionalProperties: false
                            properties:
                                digest:
                                    $ref: '#/components/schemas/Digest'
                                from:
                                    format: date-time
                                    type: string
                                to:
                                    format: date-time
                                    type: string
                            required:
                                - digest
                            type: object
                required: true
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/Replay'
                    description: The replay.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
                "404":
                    $ref: '#/components/responses/Problem'
                "409":
                    content:
                        application/problem+json:
                            schema:
                                $ref: '#/components/schemas/Problem'
                    description: The candidate no longer loads, or the audit trail does not verify. Nothing was replayed.
                "503":
                    content:
                        application/problem+json:
                            schema:
                                $ref: '#/components/schemas/Problem'
                    description: Two replays are already running, the caller's previous replay is still running, or this one did not finish within 30 seconds. No partial list.
                    headers:
                        Retry-After:
                            description: Seconds to wait before trying again.
                            schema:
                                type: integer
            summary: The recorded decisions of a period whose effect a stored candidate would change. `sefra_viewer` and above.
            tags:
                - bundles
    /v1/resume:
        post:
            operationId: resume
            requestBody:
                $ref: '#/components/requestBodies/Note'
            responses:
                "204":
                    description: The control is in the requested state; operator.action is recorded.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
            summary: Resume admission. `sefra_operator`, `sefra_admin`.
            tags:
                - controls
    /v1/stats/agents:
        get:
            operationId: getStatsAgents
            parameters:
                - $ref: '#/components/parameters/StatsFrom'
                - $ref: '#/components/parameters/StatsTo'
                - $ref: '#/components/parameters/StatsFormat'
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/StatsSeries'
                        text/csv:
                            schema:
                                type: string
                    description: The series, as JSON or, with `format=csv`, as an attachment of the same columns and rows (RFC 4180 quoting, LF line ends).
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
                "503":
                    $ref: '#/components/responses/Problem'
            summary: The 20 busiest agents. `sefra_viewer` and above.
            tags:
                - stats
    /v1/stats/approval-times:
        get:
            operationId: getStatsApprovalTimes
            parameters:
                - $ref: '#/components/parameters/StatsFrom'
                - $ref: '#/components/parameters/StatsTo'
                - $ref: '#/components/parameters/StatsFormat'
                - $ref: '#/components/parameters/StatsBucket'
                - $ref: '#/components/parameters/StatsZone'
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/StatsSeries'
                        text/csv:
                            schema:
                                type: string
                    description: The series, as JSON or, with `format=csv`, as an attachment of the same columns and rows (RFC 4180 quoting, LF line ends).
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
                "503":
                    $ref: '#/components/responses/Problem'
            summary: 'Time to approval: median and 90th percentile, approved and denied only. `sefra_viewer` and above.'
            tags:
                - stats
    /v1/stats/approvals:
        get:
            operationId: getStatsApprovals
            parameters:
                - $ref: '#/components/parameters/StatsFrom'
                - $ref: '#/components/parameters/StatsTo'
                - $ref: '#/components/parameters/StatsFormat'
                - $ref: '#/components/parameters/StatsBucket'
                - $ref: '#/components/parameters/StatsZone'
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/StatsSeries'
                        text/csv:
                            schema:
                                type: string
                    description: The series, as JSON or, with `format=csv`, as an attachment of the same columns and rows (RFC 4180 quoting, LF line ends).
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
                "503":
                    $ref: '#/components/responses/Problem'
            summary: Approvals ended, by bucket and outcome. `sefra_viewer` and above.
            tags:
                - stats
    /v1/stats/executions:
        get:
            operationId: getStatsExecutions
            parameters:
                - $ref: '#/components/parameters/StatsFrom'
                - $ref: '#/components/parameters/StatsTo'
                - $ref: '#/components/parameters/StatsFormat'
                - $ref: '#/components/parameters/StatsBucket'
                - $ref: '#/components/parameters/StatsZone'
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/StatsSeries'
                        text/csv:
                            schema:
                                type: string
                    description: The series, as JSON or, with `format=csv`, as an attachment of the same columns and rows (RFC 4180 quoting, LF line ends).
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
                "503":
                    $ref: '#/components/responses/Problem'
            summary: Executions by bucket and current status. `sefra_viewer` and above.
            tags:
                - stats
    /v1/stats/governed:
        get:
            operationId: getStatsGoverned
            parameters:
                - $ref: '#/components/parameters/StatsFrom'
                - $ref: '#/components/parameters/StatsTo'
                - $ref: '#/components/parameters/StatsFormat'
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/StatsSeries'
                        text/csv:
                            schema:
                                type: string
                    description: The series, as JSON or, with `format=csv`, as an attachment of the same columns and rows (RFC 4180 quoting, LF line ends).
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
                "503":
                    $ref: '#/components/responses/Problem'
            summary: Governed executions of every whole UTC month the period touches. `sefra_viewer` and above.
            tags:
                - stats
    /v1/stats/intents:
        get:
            operationId: getStatsIntents
            parameters:
                - $ref: '#/components/parameters/StatsFrom'
                - $ref: '#/components/parameters/StatsTo'
                - $ref: '#/components/parameters/StatsFormat'
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/StatsSeries'
                        text/csv:
                            schema:
                                type: string
                    description: The series, as JSON or, with `format=csv`, as an attachment of the same columns and rows (RFC 4180 quoting, LF line ends).
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
                "503":
                    $ref: '#/components/responses/Problem'
            summary: The 20 busiest intents. `sefra_viewer` and above.
            tags:
                - stats
    /v1/stats/refusals:
        get:
            operationId: getStatsRefusals
            parameters:
                - $ref: '#/components/parameters/StatsFrom'
                - $ref: '#/components/parameters/StatsTo'
                - $ref: '#/components/parameters/StatsFormat'
                - $ref: '#/components/parameters/StatsBucket'
                - $ref: '#/components/parameters/StatsZone'
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/StatsSeries'
                        text/csv:
                            schema:
                                type: string
                    description: The series, as JSON or, with `format=csv`, as an attachment of the same columns and rows (RFC 4180 quoting, LF line ends).
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
                "503":
                    $ref: '#/components/responses/Problem'
            summary: Refusals by bucket, code and stage. `sefra_viewer` and above.
            tags:
                - stats
    /v1/stats/rules:
        get:
            operationId: getStatsRules
            parameters:
                - $ref: '#/components/parameters/StatsFrom'
                - $ref: '#/components/parameters/StatsTo'
                - $ref: '#/components/parameters/StatsFormat'
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/StatsSeries'
                        text/csv:
                            schema:
                                type: string
                    description: The series, as JSON or, with `format=csv`, as an attachment of the same columns and rows (RFC 4180 quoting, LF line ends).
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
                "503":
                    $ref: '#/components/responses/Problem'
            summary: The 20 rules that deny most; names masked without read_payloads. `sefra_viewer` and above.
            tags:
                - stats
    /v1/stats/shares:
        get:
            operationId: getStatsShares
            parameters:
                - $ref: '#/components/parameters/StatsFrom'
                - $ref: '#/components/parameters/StatsTo'
                - $ref: '#/components/parameters/StatsFormat'
                - $ref: '#/components/parameters/StatsBucket'
                - $ref: '#/components/parameters/StatsZone'
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/StatsSeries'
                        text/csv:
                            schema:
                                type: string
                    description: The series, as JSON or, with `format=csv`, as an attachment of the same columns and rows (RFC 4180 quoting, LF line ends).
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
                "503":
                    $ref: '#/components/responses/Problem'
            summary: Rolled-back and intervention share of accepted executions. `sefra_viewer` and above.
            tags:
                - stats
    /v1/stats/summary:
        get:
            description: Computed in PostgreSQL. `to` defaults to now, `from` to 24 hours before it; at most 90 days. `executions.by_status` counts executions received in `[from, to)`; `governed` the executions accepted in the UTC month of `to`; `attention` holds counts as of now, independent of the range, each equal to one filtered list.
            operationId: getStatsSummary
            parameters:
                - in: query
                  name: from
                  schema:
                    format: date-time
                    type: string
                - in: query
                  name: to
                  schema:
                    format: date-time
                    type: string
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/StatsSummary'
                    description: The counts.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
            summary: The overview's counts. `sefra_viewer` and above.
            tags:
                - stats
    /v1/system:
        get:
            description: '`checks` are the checks of `/readyz`, run the same way, without their error text. `secrets` are the names of `sefra.yaml`''s `secrets`, each resolved by the read `/readyz` makes; never a value. `configuration` is the configuration as loaded, defaults applied; every value taken from an environment variable is shown as written (`${NAME}`), secret references as they are, nothing else hidden. `open_workflows` is null when Temporal does not answer. No parameters.'
            operationId: getSystem
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/System'
                    description: The system's status.
                "400":
                    $ref: '#/components/responses/Problem'
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
            summary: Version, roles, readiness, secrets per name, active bundle, what drain reports, effective configuration. `sefra_viewer` and above.
            tags:
                - system
    /v1/workflows/open:
        get:
            operationId: listOpenWorkflows
            responses:
                "200":
                    content:
                        application/json:
                            schema:
                                properties:
                                    more:
                                        type: boolean
                                    workflows:
                                        items:
                                            type: string
                                        type: array
                                required:
                                    - workflows
                                    - more
                                type: object
                    description: The workflows.
                "401":
                    $ref: '#/components/responses/Unauthenticated'
                "403":
                    $ref: '#/components/responses/Forbidden'
                "503":
                    $ref: '#/components/responses/Problem'
            summary: The running execution workflows, at most 1000. `sefra_viewer` and above.
            tags:
                - executions
security:
    - bearer: []
servers:
    - description: Your Sefra deployment
      url: https://sefra.example.com
tags:
    - name: approvals
    - name: executions
    - name: audit
    - name: bundles
    - name: controls
    - description: Agents and people as Sefra has seen them; Sefra has no user store.
      name: principals
    - name: system
    - name: refusals
    - name: stats
    - name: probes
