---
name: wrapup
description: End-of-session save. Captures summary, actions, decisions, rules learned, and pending items. Auto-detects Supabase if configured, otherwise saves to local markdown memory. Must run before closing the session so nothing is lost.
---

# Wrapup - End of Session Save

Trigger: User says "wrapup", "wrap up", "end session", or at the end of any working session.

## What This Skill Does

Saves ALL work from the current session so nothing is lost between conversations. Auto-detects memory backend:

- **If Supabase credentials are configured in .env** → save to Supabase (primary) + optionally update local files
- **Otherwise** → save to local `memory/` folder (markdown files)

Run through EVERY step below. Read the full conversation from top to bottom before starting.

## Compression bypass (CRITICAL)

Memory save must be full-fidelity. Before doing ANY work:

- If RTK is installed, prefix every `curl` call in this skill with `rtk proxy` so responses are not truncated.
- If Caveman mode is active, run `/caveman off` at the start of this skill, then restore the previous mode at the end. The session summary written to memory must not be compressed - future sessions load it back and need the full text.

If neither tool is installed, ignore this step.

## Step 0: Detect Memory Backend

Check if `SUPABASE_URL` and `SUPABASE_SERVICE_ROLE_KEY` are set in the project's `.env` file with non-empty values.

- If yes → Supabase backend
- If no → Local markdown backend

## Step 1: Full Session Audit (First Pass)

Walk through the conversation chronologically from first message to last. For each exchange, note:

- **Projects / clients discussed** (even briefly mentioned)
- **Actions taken** (files created or edited, commands run, API calls, reports built, deployments)
- **Tools / integrations configured** (MCPs, APIs, OAuth, new connections)
- **Decisions made** (approach chosen, options rejected, strategy agreed)
- **Rules / feedback established** (user corrections, confirmed approaches, "don't do X", "always do Y")
- **Data discovered** (account IDs, URLs, credentials filenames, property names, metrics)
- **Problems and solutions** (errors, workarounds, what didn't work and why)
- **Still pending / next** (incomplete tasks, follow-ups, things to monitor)

Do NOT proceed until this list is complete.

## Step 2: Second Pass

Go through the conversation AGAIN looking for commonly missed items:

**User corrections you glossed over:**
- Every "no", "not that", "change it to", "actually", "I meant" - each is a rule or feedback
- Every course-correction - the correction is a rule to save

**Implicit decisions:**
- Things the user approved by not objecting
- Pricing, dates, URLs, configurations confirmed during the session

**Files created, moved, renamed, or deleted:**
- Every file path that changed
- Folders created or restructured

**External systems touched:**
- Calendar events set up
- Deployment URLs established
- Third-party accounts or tools referenced

Add anything new to the audit list. If nothing new, explicitly state "Second pass complete - no additional items found."

## Step 3: Categorise Each Item

For each item in the audit list, decide where it goes:

- **Memory session record** → EVERYTHING goes here (primary). Actions, decisions, rules, data, problems, pending items.
- **Memory project record** → Update pending_items, context, or category data if project state changed
- **CLAUDE.md** → Campaign status, session log, action items, performance data
- **Not needed** → Ephemeral, already in code/git, or derivable from current state

## Step 4: Save Session to Memory

### Supabase backend

```bash
curl -s "$SUPABASE_URL/rest/v1/session_memories" \
  -H "apikey: $SUPABASE_SERVICE_ROLE_KEY" \
  -H "Authorization: Bearer $SUPABASE_SERVICE_ROLE_KEY" \
  -H "Content-Type: application/json" \
  -H "Prefer: return=representation" \
  -X POST \
  -d '<JSON payload>'
```

JSON payload:
```json
{
  "session_date": "YYYY-MM-DD",
  "project_path": "<working directory path>",
  "project_name": "<short descriptive name>",
  "summary": "<2-3 sentence overview>",
  "actions_taken": ["action 1", "action 2"],
  "decisions_made": ["decision 1", "decision 2"],
  "rules_learned": ["rule 1 with reason", "rule 2 with reason"],
  "pending_items": ["pending 1", "pending 2"],
  "data_discovered": ["data point 1"],
  "problems_and_solutions": ["problem - Solution: fix"]
}
```

### Local markdown backend

Write a new file at `memory/sessions/YYYY-MM-DD-[project-slug].md`:

```markdown
# YYYY-MM-DD - [Project Name]

**Project:** [project-key]
**Working directory:** [path]

## Summary

[2-3 sentence overview of what was accomplished]

## Actions taken

- Action 1
- Action 2

## Decisions made

- Decision 1 + reasoning
- Decision 2 + reasoning

## Rules learned

- Rule 1. WHY: [reason]
- Rule 2. WHY: [reason]

## Pending items

- Pending 1 (specific + actionable)
- Pending 2

## Data discovered

- Account IDs, URLs, filenames, metrics etc

## Problems and solutions

- Problem X → Solution Y
```

Date-prefixed filename ensures natural sort order in Finder/Explorer.

## Step 5: Update Project Record

For each project touched this session, update its record:

### Supabase backend

```bash
curl -s "$SUPABASE_URL/rest/v1/projects?project_key=eq.<KEY>" \
  -H "apikey: $SUPABASE_SERVICE_ROLE_KEY" \
  -H "Authorization: Bearer $SUPABASE_SERVICE_ROLE_KEY" \
  -H "Content-Type: application/json" \
  -X PATCH \
  -d '{"pending_items": [...]}'
```

- Remove completed items
- Add new items discovered this session
- Preserve existing items that are still pending
- Always read current pending_items first before patching

### Local markdown backend

Open `memory/projects.md`. Find the section for this project. Update the `**Pending:**` list:
- Remove completed items
- Add new items
- Preserve still-pending items

Save the file. Keep under 200 lines; archive inactive projects to `projects-archive.md` if needed.

## Step 6: Update Rules If New Ones Emerged

If the session produced new rules (cross-project rules or strong user feedback):

### Supabase backend

```bash
curl -s "$SUPABASE_URL/rest/v1/global_rules" \
  -H "apikey: $SUPABASE_SERVICE_ROLE_KEY" \
  -H "Authorization: Bearer $SUPABASE_SERVICE_ROLE_KEY" \
  -H "Content-Type: application/json" \
  -X POST \
  -d '{"rule_key": "<short-key>", "category": "feedback|pattern|reference", "content": "<rule with reason>"}'
```

### Local markdown backend

Append the rule to the relevant section of `memory/rules.md`:

```markdown
## Feedback

- [new rule]. WHY: [reason]
```

Only add genuinely new cross-project rules. Project-specific rules go in the project record.

## Step 7: Commit + Push (If Git Is Set Up)

If the project folder is a git repo and has a remote configured:

```bash
git add -A
git commit -m "session: YYYY-MM-DD - [short description]"
git push
```

This backs up the session work AND the updated memory files (if local backend). If git isn't set up, skip this step.

## Step 8: Verify

### Supabase backend

Read back the inserted session record and confirm all arrays are populated:

```bash
curl -s "$SUPABASE_URL/rest/v1/session_memories?id=eq.<ID>&select=*" \
  -H "apikey: $SUPABASE_SERVICE_ROLE_KEY" \
  -H "Authorization: Bearer $SUPABASE_SERVICE_ROLE_KEY"
```

Count items in each array. If any array that should have items is empty, the save failed - fix and retry.

### Local markdown backend

Confirm the session file was written with content in every section. Confirm projects.md was updated (diff check). Confirm rules.md was updated if new rules existed.

## Step 9: Summary

Output to the user:
- **Memory backend used:** Supabase or Local markdown
- **Session record saved** (record ID for Supabase, filename for local)
- **Project record(s) updated** (which projects, what changed)
- **Rules added** (if any)
- **Files committed + pushed** (if git was set up)
- **Key learnings saved** (bullet points)
- **Flagged for next session** (what to do, what to monitor)

## Rules

- **Always save.** Every session must be saved, no exceptions.
- **Second pass is mandatory.** First pass always misses things.
- **Update project records, not just session records.** The project record's pending_items is what /startup loads next time.
- Never fabricate - only save what was actually discussed or done this session
- Include the "why" behind rules, not just the rule
- Pending items must be specific enough that the next session can act on them without asking
- Data_discovered should include every new account ID, URL, credential filename, metric
- Problems_and_solutions should include what was tried and failed, not just the fix
- Keep memory files concise - don't paste raw transcripts
- Always read existing files before editing to avoid overwriting good content
- If the primary backend fails, fall back to the other (e.g. Supabase down → save locally, warn user)
