# Runtime Work Control Plane

CTM now treats agent work as runtime-owned state, not text inferred from the terminal.

## Goals

- Show active Wall-E turns, tools, shells, queued work, and recent completions in the session UI.
- Keep performance isolation: large terminal/tool output stays in the worker/runtime that produced it.
- Give desktop and phone the same lightweight work-state projection.
- Leave a clean adapter surface for Codex/Claude PTY workers later.

## Architecture

The authoritative runtime emits task lifecycle events. CTM stores only lightweight metadata in `runtime_tasks`:

- `ctm_session_id`, `agent_session_id`, `turn_id`
- `kind`: `turn`, `shell`, `tool`, `skill`, or `agent`
- `status`: `queued`, `running`, `stopping`, `completed`, `failed`, `cancelled`, or `stopped`
- labels, previews, provider/model, control capabilities, worker scope

Heavy artifacts are not stored in this table. Shell stdout remains in scrollback chunks or provider transcripts. Wall-E tool output remains in the Wall-E transcript/runtime stream. Task rows may point to those sources with `output_ref` later.

## Worker Process Decision

The control plane should not run heavy work in the CTM main process.

- Wall-E-owned sessions keep tool execution in the Wall-E daemon/runtime.
- Claude/Codex terminal sessions keep PTY rendering and output capture in the session host/headless terminal workers.
- CTM main process owns the small task registry and broadcasts compact `work-state` frames.
- Future worker adapters should emit the same metadata events from their session worker instead of letting the browser scrape terminal text.

This gives isolation without fragmenting the UI contract.

## UI Contract

Desktop Wall-E sessions render a compact workbar above the composer:

- chips for running work, shells, tools, skills, queued items, and isolation status
- a focused summary of the most recent active/recent task
- `Manage` opens task rows grouped into Active and Recent
- active turns expose `Stop`, which maps to the existing `walle-cancel` flow

Phone status rows consume `runtimeWork`/`runtime_work` from session payloads and show compact active-work chips.

## Adapter Rule

Each runtime adapter should emit normalized lifecycle events:

1. `startTurn`
2. `tool_call` / `tool_result`
3. `completeTurn` or `requestStop`

Adapters must never stream full stdout through `runtime_tasks`. If UI needs output, the task row should carry an `output_ref` to the existing transcript, scrollback, or artifact source.
