# Review flow and Web UI

[中文](review-flow.md) · [Back to README](../README.en.md)

## Flow

1. The plugin claims approvals only while the current preset is `auto-review`.
2. `tools/pre-execute` waits for downstream policies first. A downstream `deny` is preserved; a downstream `ask` remains an approval boundary.
3. Conservatively proven workspace-local Shell reads may be exempt. Other Shell, known network tools, and `mcp__*` are proactively reviewed by default.
4. A proactive request stores one exact target by `session + callId + live signal identity` and gives the standard approval chain a bounded human-readable reason. Copying the reason, presenting a mismatched signal, or replaying a consumed marker returns `unavailable`.
5. Guardian runs in a separate no-tools, temperature-0 stream with timeout and output limits.
6. If Guardian does not approve and `manualOverride` permits, the plugin calls the current approval listener's `next()`. This reuses DSH's native Reject / Allow once panel without cloning the request or recursively re-entering Auto Review.
7. `allowed-once` is possible only after the final JSONL audit gate succeeds.

## Latest Review lifecycle

The Host publishes `start → status → end` updates in memory and retains one latest Review snapshot for a bounded number of Sessions. Web opens a watcher for the current Session through a Typert Remote and polls roughly every 250 ms. While the current permission preset is `auto-review`, the watcher first replays the latest snapshot and then receives incremental updates.

Refresh, Session switching, and Client plugin reload reopen the watcher and recover the latest state. After a Host restart, the Remote searches the current audit JSONL and its `.1` backup for that Session's latest persisted final record and converts it into a redacted `start + end` snapshot. Results produced with auditing disabled or after an audit failure survive only for the current Host lifetime. A new `start` replaces the prior card; only matching `reviewId` status/end updates apply, so late updates cannot overwrite a newer result. Queue size, watcher count, idle lifetime, and retained snapshot count are bounded.

The plugin currently appends no `auto-review/start`, `auto-review/status`, or `auto-review/end` Session events. The former durable Session writes and Chat/Tool View/Trajectory projections remain in source with `TODO(dsh-session-events)` markers but are disabled from production entry points. Restore them only after DSH formally supports third-party log-only events whose `ignorable: true` marker survives JSONL/SQLite persistence, cold load, and Client replay end to end.

## Live card

`conversation.input.dock` shows one default-collapsed **Guardian Review** card above the composer. Its header contains the bounded target summary and Reviewing / Awaiting approval / Approved / Allowed once / Denied / Cancelled / Unavailable.

Expanding shows tool, target kind, Guardian status, concise decision reason, risk, authorization, manual approval, audit, and duration without a duplicate Status row. Full commands, URL arguments, and evidence are deliberately absent. The Guardian reason is capped at 240 characters and redacts common credentials and URL query values.

## Trajectory compatibility path

The Host schema, environment variables, and old configurations still accept `trajectoryEnabled` for backward compatibility. Web Settings currently hides that field, and the production Client does not register the Trajectory projection, so it has no UI effect for now. The old implementation and its tests remain for restoration after DSH supports safely replayable third-party Session events.

## Cancellation and failures

Request cancellation or graceful plugin disposal aborts Guardian and publishes a best-effort cancelled state. Transport, card, watcher, or history-recovery failures cannot change authorization; Guardian policy and JSONL audit-before-allow remain the safety boundary. A hard Host crash writes no new custom Session event; after restart, only results completed and successfully audited before the crash can be recovered.
