# DevTools (/docs/devtools)



DevTools is one surface in the **frontend integration**
[thematic island](/docs/concept-clusters#what-lives-outside-the-cluster-pattern) —
siblings of [react](/docs/react), [server](/docs/server),
[api-routes](/docs/api-routes), and [query](/docs/query).

In development, the runtime exposes a debugging interface on
`window.__HARNESS_DEVTOOLS__`. The surface is small on purpose —
just enough to inspect what the runtime sees, walk back through
checkpoints, and force-sync the outbox without leaving the
browser console.

Gate the wiring behind `NODE_ENV !== "production"` so the surface
doesn't ship in production bundles.

```typescript
import {
  useHarnessDevTools,
  updateDevToolsSession,
} from "@pleach/core/react";
import type { HarnessDevToolsAPI } from "@pleach/core/react";
```



## Wiring [#wiring]

Call the hook once near the provider:

```tsx
function App() {
  if (process.env.NODE_ENV !== "production") {
    // eslint-disable-next-line react-hooks/rules-of-hooks
    useHarnessDevTools();
  }
  return <HarnessProvider runtime={runtime}>...</HarnessProvider>;
}
```

Once mounted, `window.__HARNESS_DEVTOOLS__` is the active
runtime's debug surface. Refreshing the page rebuilds it.

For TypeScript shims:

```typescript
// types/global.d.ts
import type { HarnessDevToolsAPI } from "@pleach/core/react";

declare global {
  interface Window {
    __HARNESS_DEVTOOLS__?: HarnessDevToolsAPI;
  }
}
```

## The surface [#the-surface]

| Property         | Returns              | Use                                                                                                                                                                |
| ---------------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `session`        | `SessionState`       | Current full state — messages, tools, channels                                                                                                                     |
| `checkpoints()`  | `Checkpoint[]`       | List checkpoints for the current session                                                                                                                           |
| `rollback(cpId)` | `Promise<void>`      | Time-travel to a checkpoint                                                                                                                                        |
| `tools()`        | `ToolDefinition[]`   | Active tool registry                                                                                                                                               |
| `prompts()`      | `PromptCatalog`      | The composed system prompt as labeled modules — id, title, summary, mode, byte size, order                                                                         |
| `describe()`     | `RuntimeDescription` | Every customization lever (prompts / tools / safety / plugins / storage / checkpointer / provider / eventLog) + `default`/`custom` state + how to set/inspect each |
| `syncStatus()`   | `SyncStats`          | Version vectors, pending changes, last sync                                                                                                                        |
| `forceSync()`    | `Promise<void>`      | Drain the outbox now                                                                                                                                               |
| `events()`       | `HarnessEvent[]`     | Recent event log entries                                                                                                                                           |
| `interrupts()`   | `PendingInterrupt[]` | Outstanding HITL approvals                                                                                                                                         |
| `ledger()`       | `AuditableCall[]`    | In-memory audit rows (when using `MemoryProviderDecisionLedger`)                                                                                                   |

## `session` [#session]

A property, not a method. Always reflects the latest state.

```javascript
__HARNESS_DEVTOOLS__.session.messages.length
__HARNESS_DEVTOOLS__.session.pendingToolCalls
__HARNESS_DEVTOOLS__.session.versionVector
```

For React state debugging — when the UI looks stale, compare
`session` against the rendered transcript. If they disagree, the
hook's subscription got dropped.

## `checkpoints()` [#checkpoints]

Returns the checkpoint list for the current session, in creation
order (ULID-sorted).

```javascript
const cps = __HARNESS_DEVTOOLS__.checkpoints();
cps.map((c) => `${c.id} — ${c.stageId} — ${new Date(c.createdAt)}`);
```

Each checkpoint carries `id`, `sessionId`, `stageId`, `createdAt`,
and the channel snapshot map.

## `rollback(checkpointId)` [#rollbackcheckpointid]

Time-travel. Restores the session to the checkpoint and re-renders.

```javascript
await __HARNESS_DEVTOOLS__.rollback("cp_018f...");
```

The next `executeMessage` continues from the restored point.
Subsequent checkpoints are preserved by default — pass
`{ prune: true }` as a second argument to drop them:

```javascript
await __HARNESS_DEVTOOLS__.rollback("cp_018f...", { prune: true });
```

The pruning option is what you want when branching for an eval
re-run.

## `tools()` [#tools]

The currently-registered tool definitions.

```javascript
__HARNESS_DEVTOOLS__.tools().map((t) => t.name);
// → ["search_corpus", "calculator", "fetch_url"]
```

Inspect schemas:

```javascript
const tool = __HARNESS_DEVTOOLS__.tools().find((t) => t.name === "search_corpus");
console.log(tool.inputSchema, tool.description);
```

Useful when the LLM is calling a tool name you don't recognize —
verify it's actually in the registry.

## `prompts()` — see what the system prompt is made of [#prompts--see-what-the-system-prompt-is-made-of]

The composed system prompt is normally opaque. `prompts()` renders
it as an ordered list of LABELED modules — each carries an `id`, a
human-readable `title` + `summary`, its `origin` (core vs plugin),
composition `mode`, and byte size:

```javascript
__HARNESS_DEVTOOLS__.prompts().modules.forEach((m) =>
  console.log(`${m.order}. ${m.title ?? m.id} — ${m.summary ?? ""} (${m.bytes ?? "dynamic"} bytes)`),
);
```

Useful when a `systemPromptPlugin` or a `definePleachPlugin({ prompts })`
contribution isn't showing up, or you're debugging a runtime-aware
`replace` override on a `core.*` slot — you see exactly which modules
compose the prompt.

## `describe()` — every customization lever at a glance [#describe--every-customization-lever-at-a-glance]

`describe()` returns a one-shot manifest of every runtime lever
(prompts, tools, safety, plugins, storage, checkpointer, provider,
event-log), each with its `default`/`custom` state and how to set or
inspect it — the generalization of the adapter-wiring report:

```javascript
__HARNESS_DEVTOOLS__.describe().levers.forEach((l) =>
  console.log(`${l.lever}: ${l.state} — ${l.summary}`),
);
```

## `syncStatus()` [#syncstatus]

Coarse-grained sync state.

```javascript
__HARNESS_DEVTOOLS__.syncStatus();
// → {
//     local:        { clientId, vector },
//     remote:       { vector },
//     pending:      3,
//     lastSyncedAt: 1717350000000,
//     errors:       []
//   }
```

For the rich shape, the React `useSyncStatus` hook returns the
full `SyncStats` + `SyncError[]`. DevTools is the quick-look
surface.

## `forceSync()` [#forcesync]

Drains the outbox immediately rather than waiting for the next
`flushIntervalMs` tick. Returns when the cycle completes.

```javascript
await __HARNESS_DEVTOOLS__.forceSync();
__HARNESS_DEVTOOLS__.syncStatus().pending; // → 0 if cycle succeeded
```

Useful when you want to verify a write made it through before
closing the tab.

## `events()` [#events]

Recent event log entries. Returns the last N (default 100); pass
a filter for typed slices:

```javascript
__HARNESS_DEVTOOLS__.events();

__HARNESS_DEVTOOLS__.events({ types: ["tool.failed"], limit: 20 });

__HARNESS_DEVTOOLS__.events({ since: "01jc8..." });
```

The shape is the same `HarnessEvent` shape the [event log](/docs/event-log)
documents.

## `interrupts()` [#interrupts]

Outstanding HITL approvals on the current session. Useful when
the UI's approval modal isn't surfacing what the runtime is
waiting on.

```javascript
__HARNESS_DEVTOOLS__.interrupts();
// → [{ id, action_request, config, description, ... }]
```

Resolve from the console:

```javascript
const [pending] = __HARNESS_DEVTOOLS__.interrupts();
await runtime.resolveInterrupt(pending.id, { type: "accept", args: null });
```

## `ledger()` [#ledger]

The in-memory audit ledger contents. Only populated when the
runtime is configured with `MemoryProviderDecisionLedger`. Returns
empty when the production Supabase adapter is wired (use the
[query](/docs/query) API for that).

```javascript
__HARNESS_DEVTOOLS__.ledger().filter((r) => r.callClass === "synthesize");
// → typically exactly one row per turn
```

The one-synthesize-per-turn invariant is the easiest property to
spot-check from DevTools — if you see two synthesize rows for a
single `turnId`, something has drifted.

## `updateDevToolsSession(state)` [#updatedevtoolssessionstate]

The manual push API. Normally the hook subscribes to runtime
events and updates the DevTools surface automatically; this is the
escape hatch for tests or imperative state writes.

```typescript
import { updateDevToolsSession } from "@pleach/core/react";

updateDevToolsSession(synthesizedState);
```

Use sparingly. The hook subscription is the supported path.

## Diagnostics telemetry — the verbose tier [#diagnostics-telemetry--the-verbose-tier]

`window.__HARNESS_DEVTOOLS__` inspects state *at rest*. To watch the
graph *move* — which node fired, which channel bumped, which router
arm was taken — turn on the **diagnostics telemetry tier**. It's a
verbose set of engine-level [stream events](/docs/stream-events) the
runtime emits **only** when a turn runs with diagnostics enabled:

* In the [playground](/docs/cli) (a provider key is required — there
  is no keyless mode), the debug path threads `diagnostics: true` into
  the run config, so the lattice, event-log, and inspector panes light
  up node-by-node.
* Over HTTP, the same signal is `?diagnostics=1` on the route the
  playground posts to (the `runConfig.diagnostics === true` gate).

Three properties make this safe to leave wired in a debug build:

* **Off by default, byte-identical off.** A normal turn emits none of
  the diagnostics-gated fields below — the enrichments are strictly
  additive, so an off turn's stream is unchanged.
* **Zero extra cost.** The `channel.write_skipped` payload, for
  instance, is data the reducer already computed for its value-aware
  skip; diagnostics just surfaces it instead of dropping it.
* **Leak-free / agnostic.** Every field is a node NAME, a channel
  NAME, a superstep number, or a router arm LABEL. Channel *values*,
  message content, and tool arguments never ride this surface.

### The events [#the-events]

Two of these are brand-new event types; the rest are existing
[stream events](/docs/stream-events) that grow extra diagnostics-only
fields when the tier is on.

| Event                   | Diagnostics fields                                                                                 | What it's for                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ----------------------- | -------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `node.fired`            | `subscribes` (channels the node reads), `ordinal` (superstep index), `retries` (attempts consumed) | The other half of the data-flow the base event's `writes` only shows one side of — pair `subscribes` with `writes` to draw a node's in/out edges.                                                                                                                                                                                                                                                                               |
| `channel.write`         | `writer` (producing node), `ordinal`                                                               | Ties a channel bump back to the node that produced it, so a visualizer can draw the data-flow edge.                                                                                                                                                                                                                                                                                                                             |
| `channel.write_skipped` | `channel`, `reason: "no-op-bump"`, `writer?`, `ordinal?`                                           | **The silent-stall signal.** A node wrote a channel but the post-reducer value was unchanged, so the version did NOT bump and subscribers did NOT re-fire. The single most useful "why didn't the graph advance?" breadcrumb.                                                                                                                                                                                                   |
| `node.skipped`          | `node`, `reason: "arbiter-terminated"`, `ordinal?`                                                 | **The arbiter-suppression blind spot.** A node whose subscriptions were satisfied but which the synthesis-terminal arbiter latch suppressed. Distinguishes an intentional suppression from ordinary reactive quiescence (nothing subscribed) — previously invisible.                                                                                                                                                            |
| `stage.superstep`       | `step` (monotonic superstep ordinal)                                                               | The sequencing key. Correlate every `node.fired` / `channel.write` `ordinal` back to the superstep it belongs to. **Always emitted** (leak-free), diagnostics or not.                                                                                                                                                                                                                                                           |
| `route.decided`         | `from`, `to`, `arm?`, `isEnd?`                                                                     | **The branching / edge-taken signal.** A conditional router chose an arm. On the default agent graph the two routers are `shouldContinue` (post-LLM: tools / enrich / synthesize) and `afterHallucination` (post-detector: llm / citation) — see the [Edge catalog](/docs/graph-edge-catalog#the-conditional-routers). This is what tells you *which way the graph branched*, where `stage.transition` only tells you it moved. |

A worked reading of a stall: you see `stage.superstep` ticking but no
`stage.transition` — the graph looks frozen. Filter for
`channel.write_skipped` and you find the node that keeps writing an
unchanged value (`no-op-bump`), so its subscribers never re-arm. Or
you filter for `node.skipped` and find the arbiter latched a node out.
Either way the blind spot the plain stream left is now named.

Because these are [stream events](/docs/stream-events), consume them
the same way as any other — off `executeMessage()` or
`useChat({ onEvent })` — filtering on `type`:

```javascript
for await (const ev of runtime.executeMessage(sessionId, prompt, { diagnostics: true })) {
  if (ev.type === "route.decided") console.log(ev.from, "→", ev.to, `(${ev.arm})`);
  if (ev.type === "channel.write_skipped") console.warn("stalled channel:", ev.channel);
}
```

## Printing probes to the console [#printing-probes-to-the-console]

The runtime fires named probes, labels such as `[UXParity:...]`, at
decision points. Core's default sink is silent. To see them in a
terminal or the browser console, register `consoleProbeFormatter`:

```typescript
import { consoleProbeFormatter, setProbeFormatter } from "@pleach/core/instrumentation";

setProbeFormatter(consoleProbeFormatter);
```

It is a `console.log(label, serialized)` sink, so a prefix `grep` over
the output finds every probe. A formatter that throws never breaks the
call that emitted the probe. Register it in a debug build only, since it
prints on every probe.

The same function is exported from
`@pleach/core/instrumentation/emitProbe`.

## Production safety [#production-safety]

`useHarnessDevTools` does **not** check `NODE_ENV` internally —
the caller is responsible. The hook body unconditionally writes
to `window.__HARNESS_DEVTOOLS__`; ship it in production and your
production bundle gains a debug surface and a tree-shake escape
for the underlying modules.

Three options to gate it:

```tsx
// Option 1 — conditional hook (lint rule will complain; disable it):
if (process.env.NODE_ENV !== "production") {
  // eslint-disable-next-line react-hooks/rules-of-hooks
  useHarnessDevTools();
}

// Option 2 — separate dev-only component, code-split by env:
const DevTools = process.env.NODE_ENV !== "production"
  ? require("./DevTools").default
  : null;

// Option 3 — always-on but pre-stripped at build time via dead-code elimination:
if (false /* @__PURE__ */) useHarnessDevTools();
```

Option 1 is the simplest. Option 2 is the cleanest for bundle
size. Option 3 is for build pipelines that don't tree-shake
conditionals well.

## Where to go next [#where-to-go-next]

<Cards>
  <Card title="React" href="/docs/react" description="`useHarnessDevTools` and the typed `HarnessDevToolsAPI`." />

  <Card title="HarnessServer" href="/docs/server" description="Framework-agnostic handlers behind the data this surface inspects." />

  <Card title="API routes" href="/docs/api-routes" description="The HTTP + SSE wire contract feeding the session state this surface mirrors." />

  <Card title="Query" href="/docs/query" description="Server-side reads for the same audit/event data — DevTools is the in-memory peek; query is the persisted view." />

  <Card title="Stream events" href="/docs/stream-events" description="The full StreamEvent catalog the diagnostics tier enriches — node.fired, channel.write, route.decided, and the rest." />

  <Card title="Edge catalog" href="/docs/graph-edge-catalog" description="The three conditional routers `route.decided` reports on — shouldContinue, afterHallucination, and afterSynthesis." />

  <Card title="CLI" href="/docs/cli" description="`pleach dev` — the playground that runs turns with the diagnostics tier on (provider key required)." />
</Cards>
