# dsh-context redesign — use the harness natively Status: **implemented** (v0.9.0). The analysis below documents the review and the target architecture; the **Data path (host + client), the modern slot registration, and the removal of the custom RPC / polling / client cache are fully landed**. Remaining future work is scoped at the end of §5. Scope: review the plugin (v0.8.0) against the current DeepSeek Harness (master @ `47f943859b`, ~0.1.0-rc.5; npm `next` dist-tag at 0.1.0-rc.6), and define a target architecture that leans on the harness's native services, client framework, and data pipeline instead of re-implementing them. The rule of thumb the redesign follows (from the harness's own docs — `docs/subsystems/session-projection.md`): > The framework drives, the domain computes: the registry subscribes to > `session/event` once and folds every committed event through every unit; > domains hold no subscriptions and clients never fold domain events — they > receive finished values. --- ## 1. What the plugin does today (v0.8.0) Two halves shipped in one package: - **Host half** (`src/host/`, bundled to `lib/index.js`): a plain Cordis plugin (`inject: ['connection']`) that 1. folds a session's durable event log into a per-request context timeline (`fold.ts` — incremental per-session `FoldState`), 2. prices messages with its own copy of the harness's token-meter heuristic (`pricing.ts`: ~4 chars/token, block/role overhead), 3. tracks compactions/prunes via the *shadow-price* protocol (`pendingShadowedSeqs` armed by `compaction/summary`/`compaction/prune`), 4. serves the result over a **custom RPC channel** `/dsh-context` (`connection.rpc.handle`) — live sessions fold from `sessions.get(id).events`, cold sessions from `sessionQuery.readSession`, cached per session in a module-level `Map`. - **Client half** (`src/client/`, bundled to `lib/client.js` as a `window.__ModuleLoader__.load({id, factory})` closure): registers the `conversation.view` tab ("上下文/Context", order 20) and renders 1. a stats board (turns/steps/recycled/injects/switches/estimated + actuals), 2. a current-composition stacked bar + legend (system/tools/user/inject/assistant/tool) anchored to provider-reported occupancy, 3. a per-request stacked-bar history chart (step/turn granularity, ✂ compaction markers, hover tooltip, pinned detail), 4. a context-events list and a model-visible message list. Data arrives by **polling the RPC every 2s** (visibility-aware), with a per-session stale-while-revalidate cache (`cache.ts`), hand-rolled React (`react.ts` `h()` factories), `