# rye:signed:2026-04-08T05:48:59Z:122b244d258a5eaf8f86732042c0bb2ebdeb3512c37f0d1584a3695ca749e06e:gGhKzFgH6gDlNO5tIrAw8-JWqW3fsMYeJHU6gfQ0-Qh7FndTNJzKMxv7RV6NiktHXY5l2psp9ZjFVfR3K2JzBQ:6ea18199041a1ea8
# config/events.yaml
category: "agent"
tool_type: "config"
version: "1.0.0"
description: "Thread event type definitions, payload schemas, and criticality levels"
schema_version: "1.0.0"

event_types:
  thread_started:
    category: lifecycle
    criticality: critical
    description: "Thread execution begins"
    payload_schema:
      type: object
      required: [directive, model]
      properties:
        directive: { type: string }
        model: { type: string }
        limits: { type: object }

  thread_continued:
    category: lifecycle
    criticality: critical
    description: "Continuation thread execution begins (handoff from prior thread)"
    payload_schema:
      type: object
      required: [directive, model, previous_thread_id]
      properties:
        directive: { type: string }
        model: { type: string }
        previous_thread_id: { type: string }
        limits: { type: object }

  thread_completed:
    category: lifecycle
    criticality: critical
    payload_schema:
      type: object
      required: [cost]
      properties:
        cost: { type: object }

  thread_suspended:
    category: lifecycle
    criticality: critical
    payload_schema:
      type: object
      required: [suspend_reason]
      properties:
        suspend_reason: { type: string, enum: [limit, error, budget, approval] }

  thread_cancelled:
    category: lifecycle
    criticality: critical
    payload_schema:
      type: object
      properties:
        reason: { type: string }

  system_prompt:
    category: cognition
    criticality: critical
    description: "System prompt assembled from context layers (identity, behavior, protocol)"
    payload_schema:
      type: object
      required: [text]
      properties:
        text: { type: string }
        layers: { type: array, items: { type: string } }

  context_injected:
    category: cognition
    criticality: critical
    description: "Hook-injected context blocks (environment, completion) added to user message"
    payload_schema:
      type: object
      required: [position, blocks]
      properties:
        position: { type: string, enum: [before, after] }
        blocks:
          type: array
          items:
            type: object
            properties:
              id: { type: string }
              content: { type: string }

  cognition_in:
    category: cognition
    criticality: critical
    description: "Prompt sent to LLM"
    payload_schema:
      type: object
      required: [text, role]
      properties:
        text: { type: string }
        role: { type: string, enum: [system, user, developer] }
        directive: { type: string }

  cognition_out:
    category: cognition
    criticality: critical
    emit_on_error: true
    payload_schema:
      type: object
      required: [text]
      properties:
        text: { type: string }
        model: { type: string }
        is_partial: { type: boolean, default: false }
        truncated: { type: boolean, default: false }
        error: { type: string }
        completion_percentage: { type: number, minimum: 0, maximum: 100 }

  cognition_out_delta:
    category: cognition
    criticality: droppable
    description: "Streaming text chunk"
    emit_config:
      async: true
      throttle_seconds: 0.1
    payload_schema:
      type: object
      required: [text]
      properties:
        text: { type: string }
        chunk_index: { type: integer }
        is_final: { type: boolean }

  cognition_reasoning:
    category: cognition
    criticality: droppable
    emit_on_error: true
    emit_config:
      accumulate_on_error: true
    payload_schema:
      type: object
      required: [text]
      properties:
        text: { type: string }
        is_partial: { type: boolean }
        was_interrupted: { type: boolean }

  tool_call_start:
    category: tool
    criticality: critical
    payload_schema:
      type: object
      required: [tool, call_id, input]
      properties:
        tool: { type: string }
        call_id: { type: string }
        input: { type: object }

  tool_call_result:
    category: tool
    criticality: critical
    payload_schema:
      type: object
      required: [call_id]
      properties:
        call_id: { type: string }
        output: { type: string }
        error: { type: string }
        duration_ms: { type: integer }

  error_classified:
    category: error
    criticality: critical
    payload_schema:
      type: object
      required: [error_code, category]
      properties:
        error_code: { type: string }
        category: { type: string }
        retryable: { type: boolean }

  limit_escalation_requested:
    category: error
    criticality: critical
    payload_schema:
      type: object
      required: [limit_code]
      properties:
        limit_code: { type: string }
        current_value: { type: number }
        current_max: { type: number }

  child_thread_started:
    category: orchestration
    criticality: critical
    payload_schema:
      type: object
      required: [child_thread_id, child_directive]
      properties:
        child_thread_id: { type: string }
        child_directive: { type: string }
        parent_thread_id: { type: string }

criticality_levels:
  critical:
    description: "Synchronous, blocking write"
    durability: guaranteed
    async: false

  droppable:
    description: "Fire-and-forget async emission"
    durability: best_effort
    async: true
    fallback: drop
