# @mwillbanks/tuil-protocol

Source: /tuil/docs/reference/packages/protocol
Locale: en

Versioned in-process and remote-ready runtime inspection protocol for tuil.



## Overview [#overview]

Versioned in-process and remote-ready runtime inspection protocol for tuil.

`@mwillbanks/tuil-protocol` is independently installable and also participates in the
umbrella `@mwillbanks/tuil` runtime where applicable.

## Installation [#installation]

<CodeBlockTabs defaultValue="npm">
  <CodeBlockTabsList>
    <CodeBlockTabsTrigger value="npm">
      npm
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="pnpm">
      pnpm
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="yarn">
      yarn
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="bun">
      bun
    </CodeBlockTabsTrigger>
  </CodeBlockTabsList>

  <CodeBlockTab value="npm">
    ```bash
    npm install @mwillbanks/tuil-protocol
    ```
  </CodeBlockTab>

  <CodeBlockTab value="pnpm">
    ```bash
    pnpm add @mwillbanks/tuil-protocol
    ```
  </CodeBlockTab>

  <CodeBlockTab value="yarn">
    ```bash
    yarn add @mwillbanks/tuil-protocol
    ```
  </CodeBlockTab>

  <CodeBlockTab value="bun">
    ```bash
    bun add @mwillbanks/tuil-protocol
    ```
  </CodeBlockTab>
</CodeBlockTabs>

## How it operates [#how-it-operates]

The devtools protocol defines versioned messages, in-process transport, and safe-by-default session recording, import, export, and deterministic replay. Every recorded payload is recursively cloned and redacted before it can appear in a recorder snapshot or export.

<Mermaid
  chart="flowchart LR
  S0[&#x22;connect&#x22;]
  S1[&#x22;negotiate version&#x22;]
  S2[&#x22;exchange&#x22;]
  S3[&#x22;record/replay&#x22;]
  S4[&#x22;close&#x22;]
  S0 --> S1
  S1 --> S2
  S2 --> S3
  S3 --> S4"
/>

## API [#api]

| API                                                                                      | Signature                        | Description                            |
| ---------------------------------------------------------------------------------------- | -------------------------------- | -------------------------------------- |
| [`protocolLimits`](/tuil/docs/reference/packages/protocol/api/protocol-limits)                | `constant protocolLimits`        | Public constant protocolLimits.        |
| [`ProtocolMessageType`](/tuil/docs/reference/packages/protocol/api/protocol-message-type)     | `type ProtocolMessageType`       | Public type ProtocolMessageType.       |
| [`protocolRedactedValue`](/tuil/docs/reference/packages/protocol/api/protocol-redacted-value) | `constant protocolRedactedValue` | Public constant protocolRedactedValue. |
| [`protocolVersion`](/tuil/docs/reference/packages/protocol/api/protocol-version)              | `constant protocolVersion`       | Public constant protocolVersion.       |

## Events and lifecycle [#events-and-lifecycle]

Versioned envelopes distinguish requests, responses, notifications, and protocol errors. Validation fails closed on envelope fields, ids, timestamps, payload JSON shape, nesting, message count, and byte limits. Sensitive keys, credentials, JWTs, and URL userinfo are removed recursively; use `redactProtocolValue` for non-envelope devtools data and `sanitizeProtocolMessage` for complete messages.

All subscriptions and registrations return a disposer or belong to an owning
runtime that disposes them in reverse order.

## Example [#example]

```tsx
import { InProcessProtocolTransport, redactProtocolValue } from "@mwillbanks/tuil-protocol";

const transport = new InProcessProtocolTransport();
const safeSnapshot = redactProtocolValue(runtimeSnapshot);
```

## Related [#related]

* [Package architecture](/tuil/docs/concepts/packages)
* [Events](/tuil/docs/concepts/events)
* [Testing](/tuil/docs/guides/testing)
