# v8.5 Session Integrity + Recovery Ops Implementation Plan

> **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.

**Goal:** Add robust session-integrity diagnostics and recovery operations for Engram so operators can detect crash-like continuity failures and recover safely.

**Architecture:** Build a non-destructive session integrity subsystem around transcript/checkpoint metadata, with explicit diagnostics, recovery guidance, and bounded repair operations. Keep high-risk operations human-confirmed and fail-open for normal runtime.

**Tech Stack:** TypeScript, `src/transcript.ts`, `src/orchestrator.ts`, `src/cli.ts`, OpenClaw hook events, node:test.

---

## Requirements

1. Detect and report continuity anomalies (incomplete turns, broken chains, invalid checkpoint metadata).
2. Provide dry-run integrity report before any repair action.
3. Add repair actions that only touch Engram-managed artifacts by default.
4. Require explicit `--allow-session-file-repair` for OpenClaw session file mutation paths.
5. Never perform automatic pointer/session rewiring.

## Task 1: Session integrity analyzer

**Files:**
- Create: `src/session-integrity.ts`
- Test: `tests/session-integrity.test.ts`

## Task 2: CLI diagnostics and repair commands

**Files:**
- Modify: `src/cli.ts`
- Test: `tests/cli-session-integrity.test.ts`

Commands:
- `openclaw engram session-check`
- `openclaw engram session-repair --dry-run`
- `openclaw engram session-repair --apply`

## Task 3: Recovery summary surface

**Files:**
- Modify: `src/orchestrator.ts`
- Modify: `src/transcript.ts`
- Test: `tests/recovery-summary.test.ts`

## Task 4: Safety + docs

**Files:**
- Modify: `docs/operations.md`
- Modify: `docs/config-reference.md`
- Modify: `CHANGELOG.md`

