---
name: audit-end
description: End an audit session with integrity checks and summary. Use when the user says "/end", "done", "pause", or when the current task is complete.
---

# /end — Audit Session End + Integrity Check

## Trigger

```
/end
```

## Steps

### 1. Determine current session

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

If missing:
- Check for `auto_` sessions (hook-created)
- If none, report "No active session"

### 2. Collect audit data

Sources:
- `.boo/runs/audit_buffer.jsonl` — hook-recorded Write/Edit/Bash ops
- `.boo/runs/audit_pending.jsonl` — agent [AUDIT] blocks
- `.boo/runs/{session_id}/audit_trail.jsonl` — previously flushed records

Steps:
1. Read buffer + pending remaining data
2. Append to `audit_trail.jsonl`
3. Clear buffer + pending files

### 3. Extract user corrections

Scan audit_trail for `user_correction` records:

```json
{
  "record_type": "conversation",
  "action_type": "user_correction",
  "priority": "critical_for_recovery",
  "timestamp": "<ISO 8601>",
  "original_claim": "<what agent said>",
  "correction": "<what user corrected>",
  "principle_extracted": "<general principle>",
  "persisted_to": ["CLAUDE.md", ".boo/guidelines/..."]
}
```

### 4. Integrity checks

| Check | Condition | Fail |
|-------|-----------|------|
| Has records | audit_trail lines > 0 | ⚠️ "Zero audit records" |
| Files covered | Write/Edit entries exist for modified files | ⚠️ List uncovered files |
| Corrections persisted | persisted_to is non-empty for each correction | ⚠️ Remind to persist |

Output:
```
=== Session Audit Check ===
Session: <id>
Task: <task>
Duration: <start → end>

[✅] Records: N
[⚠️] Files not in audit: <list>
[✅] Corrections persisted: M
```

### 5. Generate session summary

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

```
# Session Summary | <id>
## Task: <description>
## Time: <start → end>
## Status: completed

## Completed
- <action list>

## User Corrections
- <correction records>

## Stats
- Records: N
- Corrections: M
```

### 6. Update state

- Set `session.json status = "completed", end_time = now()`
- Update `index.json` entry
- Clear `.current_session`

## Notes

- Save even if checks find problems — recording > perfection
- ⚠️ = don't block save; ❌ = warn user, still save
- /end itself may trigger one more Stop hook flush — normal
