---
name: command-end
description: End the current audit session, flush remaining buffer data, run integrity checks, and generate a session summary. Use when finishing a task, taking a break, or ending work. Examples: "end", "finish session", "end session", "wrap up", "/end".
allowed-tools:
  - Read
  - Glob
  - Grep
  - Bash
  - Write
---

# /end — Audit Session End + Integrity Check

## Trigger

```
/end
```

## Steps

### 1. Find current session

Read `.boo/runs/.current_session` for the session_id.

If absent, check for auto-created sessions. If none, report "No active session."

### 2. Collect remaining audit data

Read `.boo/runs/audit_buffer.jsonl` and `audit_pending.jsonl` for any data the Stop hook hasn't flushed yet. Append both to `.boo/runs/{session_id}/audit_trail.jsonl`, then clear the buffer files.

### 3. Extract user corrections

Scan `audit_trail.jsonl` for `user_correction` entries. Each should have a non-empty `persisted_to` array. If any are unpersisted, flag them.

### 4. Integrity checks

| Check | Source | Pass | Fail |
|-------|--------|------|------|
| Has records | trail line count | > 0 | Warn |
| Files tracked | tool=Write/Edit entries | Every changed file has an entry | Warn |
| Corrections persisted | user_correction entries | persisted_to non-empty | Warn |

### 5. Generate summary

Write `.boo/runs/{session_id}/session_summary.md`:

```markdown
# Session Summary | {session_id}
## Task: {description}
## Time: {start} → {end}
## Status: completed

Completed work: {action list}
Key conclusions: {output entries}
User corrections: {correction records}
```

### 6. Close

Update `session.json`: status=completed, end_time=now. Update `index.json`. Delete `.current_session`.
