> ## Documentation Index
> Fetch the complete documentation index at: https://docs.10et.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Flows

> Declarative event-driven automation — cron triggers, event patterns, agent spawns, approval gates

Flows are YAML-defined automations that react to events. When something happens in your project, flows trigger actions automatically.

## Where they live

```
.tenet/flows/
├── self-driving.yaml      # autonomous improvement loop
├── cross-service.yaml     # multi-repo cascade
└── scripts/               # bash scripts for complex actions
```

## Structure

```yaml theme={null}
flows:
  - name: auto-merge-on-improvement
    description: "Auto-merge PRs when eval score improves"
    enabled: true
    trigger:
      pattern: "eval:scored"
      condition: 'data.improved == "true"'
    gate:
      requires_approval: false
      cooldown_hours: 4
    actions:
      - type: log
        message: "Eval passed: {{data.agent}} delta={{data.delta}}"
      - type: command
        command: "gh pr merge {{data.pr_number}} --auto"
      - type: journal
        entry_type: milestone
        title: "Auto-merged PR #{{data.pr_number}}"
```

## Triggers

| Pattern                 | When it fires                              |
| ----------------------- | ------------------------------------------ |
| `eval:scored`           | After any eval completes                   |
| `scope:impact`          | Cross-service impact detected              |
| `session:ended`         | Agent or human session ends                |
| `cron:nightly`          | Nightly schedule                           |
| `cron:every-30-minutes` | Every 30 min                               |
| `custom:*`              | Your own events via `tenet events publish` |

## Gates

Control when flows actually execute:

```yaml theme={null}
gate:
  requires_approval: true    # human must approve
  cooldown_hours: 4          # don't re-trigger within 4h
  max_iterations: 1          # only run once per trigger
```

## Actions

| Type      | What it does                 |
| --------- | ---------------------------- |
| `command` | Run a shell command          |
| `journal` | Write a journal entry        |
| `log`     | Log a message                |
| `spawn`   | Spawn an agent in a worktree |

## The Self-Driving Loop

The default `self-driving.yaml` closes the autonomous improvement loop:

```
Issue filed (tenet/backlog label)
  → PP picks up issue
  → Agent creates PR in worktree
  → Eval runs on PR
  → Score improves → auto-merge → close issue → tenet/done
  → Score regresses → revert → log → try different approach tomorrow
```

## Commands

```bash theme={null}
tenet flows list              # see all flows and their status
tenet flows enable <name>     # activate a flow
tenet flows disable <name>    # deactivate
tenet flows run <name>        # trigger manually
tenet events recent           # see recent events
tenet events publish custom:my-event  # emit your own
```

## Cross-Service Cascade

When services declare `produces` and `consumes` scopes, flows detect impact:

```yaml theme={null}
- name: cascade-cross-service
  trigger:
    pattern: "scope:impact"
  actions:
    - type: spawn
      target: worktree
      command: tenet peter agent {{data.affected_agent}} -r 3
```

API changes automatically trigger evals in downstream consumers.
