# v8.7 Custom Memory Routing Rules Implementation Plan

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

**Goal:** Add user-configurable routing rules that direct extracted memories into target categories/namespaces based on deterministic matching.

**Architecture:** Implement a validated route-rule engine with priority ordering and testable matching, applied during write-time classification after extraction but before persistence.

**Tech Stack:** TypeScript, `src/routing/*`, `src/orchestrator.ts`, `src/config.ts`, `src/cli.ts`, node:test.

---

## Requirements

1. Route rules support regex and keyword patterns.
2. Deterministic priority order; first highest-priority match wins.
3. Safe target validation (no path traversal, only allowed categories/namespaces).
4. CLI for list/add/remove/test rules.
5. Rule engine fully optional and disabled by default.

## Task 1: Routing engine

**Files:**
- Create: `src/routing/engine.ts`
- Test: `tests/routing-engine.test.ts`

## Task 2: Config and persisted rules

**Files:**
- Modify: `src/types.ts`
- Modify: `src/config.ts`
- Create: `src/routing/store.ts`
- Test: `tests/routing-store.test.ts`

## Task 3: CLI management commands

**Files:**
- Modify: `src/cli.ts`
- Test: `tests/cli-routing-commands.test.ts`

Commands:
- `openclaw engram route list`
- `openclaw engram route add <pattern> <target>`
- `openclaw engram route remove <pattern>`
- `openclaw engram route test <text>`

## Task 4: Orchestrator wiring + docs

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

