# rye:signed:2026-04-14T02:15:39Z:7a921291d722b81287cb77677ab04750cdbca0ce02917a017f7eb602920db86c:TutfkeU4j9buGDC9293FQQLka0tWt92Aq8o1phhmv1PLwGbpqBU51boZokXdVNs1TIW4mEtOS6pz7TItSkNWDA:6ea18199041a1ea8
# config/hook_conditions.yaml
category: "agent"
tool_type: "config"
version: "1.0.0"
description: "Built-in and infrastructure hook definitions for thread lifecycle events"
schema_version: "1.0.0"

builtin_hooks:
  - id: "default_retry_transient"
    event: "error"
    layer: 2
    condition:
      path: "classification.retryable"
      op: "eq"
      value: true
    action:
      primary: "execute"
      item_type: "tool"
      item_id: "rye/agent/threads/internal/control"
      params:
        action: "retry"
    description: "Retry errors classified as retryable"

  - id: "default_fail_permanent"
    event: "error"
    layer: 2
    condition:
      path: "classification.category"
      op: "eq"
      value: "permanent"
    action:
      primary: "execute"
      item_type: "tool"
      item_id: "rye/agent/threads/internal/control"
      params:
        action: "fail"
        error: "${error.message}"
    description: "Fail on permanent errors"

  - id: "default_abort_cancelled"
    event: "error"
    layer: 2
    condition:
      path: "classification.category"
      op: "eq"
      value: "cancelled"
    action:
      primary: "execute"
      item_type: "tool"
      item_id: "rye/agent/threads/internal/control"
      params:
        action: "abort"
    description: "Abort on cancellation"

  - id: "default_escalate_limit"
    event: "limit"
    layer: 2
    condition:
      path: "limit_code"
      op: "in"
      value: ["spend_exceeded", "turns_exceeded", "tokens_exceeded", "duration_seconds_exceeded", "spawns_exceeded", "depth_exceeded"]
    action:
      primary: "execute"
      item_type: "tool"
      item_id: "rye/agent/threads/internal/control"
      params:
        action: "escalate"
        limit_type: "${limit_code}"
        current_value: "${current_value}"
    description: "Escalate limit hits for approval"

  - id: "default_context_compaction"
    event: "context_window_pressure"
    layer: 2
    condition:
      path: "pressure_ratio"
      op: "gte"
      value: 0.8
    action:
      primary: "execute"
      item_type: "directive"
      item_id: "rye/agent/threads/default_compaction"
      params:
        pressure_ratio: "${event.pressure_ratio}"
        tokens_used: "${event.tokens_used}"
    description: "Trigger context compaction"

  - id: "default_directive_return"
    event: "directive_return"
    layer: 2
    action:
      primary: "execute"
      item_type: "tool"
      item_id: "rye/agent/threads/internal/emitter"
      params:
        event_type: "directive_return"
        thread_id: "${thread_id}"
        payload:
          outputs: "${outputs}"
          cost: "${cost}"
    description: "Emit directive_return event for observability"

infra_hooks:
  - id: "infra_save_state"
    event: "after_step"
    layer: 3
    action:
      primary: "execute"
      item_type: "tool"
      item_id: "rye/agent/threads/internal/emitter"
      params:
        event_type: "checkpoint_saved"
        thread_id: "${thread_id}"
        payload:
          turn: "${cost.turns}"

  - id: "infra_completion_signal"
    event: "after_complete"
    layer: 3
    action:
      primary: "execute"
      item_type: "tool"
      item_id: "rye/agent/threads/internal/emitter"
      params:
        event_type: "thread_completed"
        thread_id: "${thread_id}"
        payload:
          cost: "${cost}"

# Identity, Behavior, and ToolProtocol removed — delivered via extends chain
# and permission-driven tool schema preload (see layered-context-injection-design.md).
# Directives that need them should extend rye/agent/core/base or be routed via
# resolve_extends hooks.

context_hooks:
  - id: "ctx_directive_instruction"
    event: "thread_started"
    layer: 2
    position: "after"
    wrap: false
    action:
      primary: "execute"
      item_type: "knowledge"
      item_id: "rye/agent/core/DirectiveInstruction"
    description: "Inject directive execution instruction after directive body"

action_primaries: ["execute", "fetch", "sign"]

action_item_types: ["directive", "tool", "knowledge"]
