> ## Documentation Index
> Fetch the complete documentation index at: https://critiqor.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Critiqor Architecture: CLI, Observation Engine, and Plugin

> Critiqor separates CLI routing from runtime supervision. A bundled plugin captures OpenClaw evidence; the observation engine generates diagnosis artifacts.

Critiqor is built on two distinct layers that never mix their concerns. The **CLI layer** handles everything the user touches: parsing commands, rendering help text, validating options, and routing to the right backend function. The **Supervised Runtime layer** handles everything that happens at runtime: creating sessions, launching `openclaw chat` as a child process, owning that process lifecycle, persisting evidence written by the bundled plugin, and driving finalization into a structured diagnosis.

This separation means the CLI has no knowledge of what OpenClaw is doing, and the runtime has no knowledge of how the user invoked it. You can call the runtime functions directly from Python without going through Click at all.

## Architecture at a Glance

| Layer              | Responsibility                                                                                       | Does NOT do                                          |
| ------------------ | ---------------------------------------------------------------------------------------------------- | ---------------------------------------------------- |
| CLI Layer (Click)  | Parse commands, render help, validate options, route to backend                                      | Launch OpenClaw, observe runtime, generate diagnoses |
| Supervised Runtime | Create sessions, launch `openclaw chat`, own the child process, persist evidence, finalize diagnoses | Render CLI help or parse arguments                   |

## Full Session Pipeline

Every monitored run travels through this pipeline from the moment you invoke `critiqor monitor openclaw` to the moment the local dashboard opens:

```
critiqor monitor openclaw
       ↓
OpenClaw (child process)
       ↓
Critiqor OpenClaw Plugin (bundled, auto-loaded)
       ↓
runs/<run_id>/session.json  (raw evidence)
       ↓
critiqor finalize
       ↓
Diagnosis Engine
       ↓
runs/<run_id>/diagnosis.json  (structured findings)
       ↓
Local Dashboard
```

The plugin is bundled inside the Critiqor package under `critiqor/clawhub/critiqor-openclaw/` and is loaded automatically by setting `OPENCLAW_BUNDLED_PLUGINS_DIR` in the child process environment before OpenClaw starts. No manual plugin installation is required.

## What Each Stage Does

**`critiqor monitor openclaw`** — The CLI validates your options and calls `SupervisedOpenClawRuntime.run()`. The runtime creates a session record, sets environment variables that carry run context into the child process, then spawns `openclaw chat` (or a custom command via `--openclaw-command`).

**OpenClaw (child process)** — Runs normally. The user interacts with it as they would without Critiqor. The only difference is that the bundled plugin is auto-loaded via the environment variable injected by the runtime.

**Critiqor OpenClaw Plugin** — A passive JavaScript observer registered through OpenClaw's extension API. It hooks into tool lifecycle events and timeline events without modifying any agent code. Every captured event is appended to `runs/<run_id>/session.json` in real time.

**`critiqor finalize`** — The CLI calls `finalize_observation()`. The runtime reads the active session, merges internal lifecycle events with the plugin evidence from `session.json`, runs the diagnosis engine, and writes `diagnosis.json`. The local dashboard is then served automatically unless `--no-dashboard` is passed.

## Learn More

* [Observation Engine](/architecture/observation-engine) — Session lifecycle, state machine, file structure, and how events flow from two sources into a single finalized record.
* [OpenClaw Plugin](/architecture/openclaw-plugin) — How the bundled plugin hooks into OpenClaw's runtime event system, what it collects, and how event normalization works.
