<!-- source-hash: 445fe5d7652052e5502c2026ce010a3c -->
Portable wire-contract utilities and text helpers for slash-command dispatch, shared between the lib layer and hub UI chat surfaces.

## Key Components

| Export | Type | Description |
|--------|------|-------------|
| `WireCommandOverride` | Interface | Client-safe wire shape for chat request bodies; excludes `systemPromptAddendum` to prevent Rule-5b injection |
| `CommandOverride` | Interface | Server-built dispatch result passed to `buildChatContext`; includes entity lookup, ID filter, browse scope, and presentation hint |
| `parseWireCommandOverride` | Function | Validates and parses raw wire input; enforces regex + length constraints on `entityIdFilter` and `retrievalQueryOverride` |
| `extractEntityIdFilter` | Function | Safely resolves `entityIdFilter` from a `CommandOverride`, with optional `tableId` narrowing |
| `sanitizeTitleForChat` | Function | Collapses control characters (`\r`, `\n`, `\t`) in free-text titles to single spaces |
| `formatSingularLookupInvocation` | Function | Builds a `/cmd "value"` string with two-pass backslash/quote escaping for safe re-parsing |
| `buildDiscussAddendum` | Function | Composes a server-trusted system-prompt addendum for the inline object-card "Discuss" action |

## Usage Example

```typescript
import {
  parseWireCommandOverride,
  extractEntityIdFilter,
  formatSingularLookupInvocation,
  buildDiscussAddendum,
} from './slash-dispatch-utils'

// Validate incoming wire payload
const override = parseWireCommandOverride(req.body.commandOverride)
// override is null if malformed; typed WireCommandOverride if valid

// Narrow to a specific table
const filter = extractEntityIdFilter(override, 'tickets')
if (filter) {
  const { tableId, id } = filter // safe, both non-empty and tableId === 'tickets'
}

// Build a user-visible slash invocation
const msg = formatSingularLookupInvocation('ticket', 'Fix "login" bug\\path')
// → /ticket "Fix \"login\" bug\\path"

// Compose a Discuss addendum server-side (never from wire input)
const addendum = buildDiscussAddendum({ tableId: 'tickets', id: 'tkt-001' })
```

> **Security note:** `systemPromptAddendum` is intentionally absent from `WireCommandOverride`. Addendum text is always composed server-side via `buildDiscussAddendum` from trusted values, preventing arbitrary prompt injection from the client.