> ## Documentation Index
> Fetch the complete documentation index at: https://docs.manthan.systems/llms.txt
> Use this file to discover all available pages before exploring further.

# replay

> @parmana/replay — a real deterministic replay engine, currently unused by the API

`@parmana/replay` (`packages/replay/src/index.ts`) exports `ReplayEngine`, `ReplayBuilder`, `ReplayVerifier`, a `ReplayContext` type, and an engine sub-layer (`ReplayPipeline`, `ReplayExecutor`, `ReplayPlan`), plus `ReplayError`.

<Warning>
  **This package is not imported anywhere under `packages/runtime` or `packages/api`.** What `POST /replay` actually does is a hash-integrity check via `@parmana/crypto`'s `VerificationCrypto` — see [REST API → Replay](/docs/api/replay) for the full trace through `ExecutionTrustApplication.replay()`. Everything below describes real, working code that a future integration could wire in, not what runs today when you call the endpoint.
</Warning>

## `ReplayEngine`

```ts theme={null}
class ReplayEngine {
  replay(input: ReplayInput): ReplayResult;
}

interface ReplayInput {
  trustRecord: ExecutionTrustRecord;
  transaction: BusinessTransaction;
  policy?: Policy;
}

interface ReplayResult {
  recordedDecision: Decision;
  replayedDecision: Decision;
  matches: boolean;
  replayedAt: Date;
}
```

`ReplayEngine.replay()` (`packages/replay/src/ReplayEngine.ts`) takes the recorded Decision from `trustRecord.executions[0].decision`, re-runs `PolicyEngine.evaluate()` (from [`policy`](/docs/packages/policy)) against the transaction's signals and the supplied policy, builds a `replayedDecision`, and sets `matches = recordedDecision.outcome === replayedDecision.outcome`. This is genuine deterministic decision replay — a materially different (and stronger) check than a hash comparison, since it independently re-derives the policy outcome rather than just confirming the record wasn't tampered with.

<Note>
  This `ReplayResult` (`recordedDecision`/`replayedDecision`/`matches`/`replayedAt`) is a completely different shape from the `ReplayResult` that `POST /replay` and both SDKs actually return (`businessTransactionId`/`trustRecordHash`/`verified` — see [Concepts → Replay](/docs/concepts/replay)). Same name, two different types, in two different packages.
</Note>

`ReplayEngine.replay()` also logs recorded vs. replayed outcomes and the intermediate policy decision to the console (labeled `"Temporary debug output"` in the source) on every call — noisy if you do wire this in as-is.

## `ReplayBuilder`

```ts theme={null}
class ReplayBuilder {
  constructor(context: ReplayContext);
  build(): ReplayEngine;
}
```

Currently just constructs a plain `new ReplayEngine()` regardless of the context passed in — the context isn't yet used to configure anything.

## Engine sub-layer

`packages/replay/src/engine/` — `ReplayPipeline`, `ReplayExecutor`, `ReplayPlan` — a staged execution model parallel to `runtime`'s own `RuntimePipeline`/`RuntimeComponent`, intended for more elaborate multi-step replay scenarios than the single-shot `ReplayEngine.replay()` call above.

## Related

<CardGroup cols={2}>
  <Card title="Replay (concept)" href="/docs/concepts/replay">What replay is meant to guarantee.</Card>
  <Card title="REST API → Replay" href="/docs/api/replay">What actually runs when you call `POST /replay`.</Card>
  <Card title="policy" href="/docs/packages/policy">The `PolicyEngine` this package re-invokes.</Card>
  <Card title="verification" href="/docs/packages/verification">The other unused-by-the-API engine package.</Card>
</CardGroup>
