# Proactive layer

While the agent works the framework watches and steps in: blocks dangerous commands, reminds about missing tests, notices a stuck model. Everything that happens becomes an event; rules subscribe to events and decide.

| Part | What | State |
| --- | --- | --- |
| Event foundation | One unified stream anyone can subscribe to. Proactive is its first consumer | Running: bus on, both source classes emit, `tool.before` has the synchronous query point, Web UI is an ordinary subscriber |
| Proactive rules | Policies subscribe and step in. Decoupled from the foundation | Code in `openprogram/runtime/proactive/`, not installed at worker start |

## Event foundation

1. [Event reference](https://fzkuji.github.io/OpenProgram/docs/reference/design/proactive/event-reference.html): every event type with payload, timing and source; the API and its three usages (observe, intercept, ask). Check it first when looking up an event.
2. [Event layer](https://fzkuji.github.io/OpenProgram/docs/reference/design/proactive/event-layer.html): the Event model, the two source classes, where the bus sits. [Diagram](https://fzkuji.github.io/OpenProgram/docs/reference/design/proactive/event-layer.html).
3. [Framework evolution](https://fzkuji.github.io/OpenProgram/docs/reference/design/proactive/framework-evolution.html): why routing through the Web UI leaves gaps, what the bus gives each role, what stays untouched. [Diagram](https://fzkuji.github.io/OpenProgram/docs/reference/design/proactive/framework-evolution.html).

## Proactive rules

1. [Overview](https://fzkuji.github.io/OpenProgram/docs/reference/design/proactive/overview.html): one `rm -rf` blocked end to end, with rules, interventions and state explained in place.
2. [Events and state](https://fzkuji.github.io/OpenProgram/docs/reference/design/proactive/events-and-state.html): state folded from events, which lets rules remember.

| Page | Covers |
| --- | --- |
| [Execution model](https://fzkuji.github.io/OpenProgram/docs/reference/design/proactive/execution-model.html) | Writing a Policy; blocking and observing kinds |
| [MVP policies](https://fzkuji.github.io/OpenProgram/docs/reference/design/proactive/policies-mvp.html) | Three rules to copy |
| [Invariants](https://fzkuji.github.io/OpenProgram/docs/reference/design/proactive/invariants.html) | What the framework must hold, chiefly no self-triggered loops |

## Short answers

- **New framework or patch?**: A standalone layer reusing the event bus, tool approval and background tasks.
- **Rules are written in?**: Plain Python classes. No config file or DSL.
- **How heavy?**: Events, state, rules, stepping in. Tamper resistance, offline replay verification and adversarial safety are in `_research_archive/`.
- **Where is the log?**: Always on. `~/.openprogram/projects/<project-id>/chats/<sid>/events.jsonl`, or `~/.openprogram/logs/events.jsonl` outside a session.

[Event reference](https://fzkuji.github.io/OpenProgram/docs/reference/design/proactive/event-reference.html)
