# Closing a session

Triggered by "Close the session", "close", "wrap up", "that's it for today",
or when the founder signals the end of a working block.

**The close is a transaction, not an essay.** Its product is one filled-in
`scripts/close.sql` that the founder reads and runs. It either lands
completely or not at all. Prose summaries are not a close.

---

## 1. Every thread touched → closed or re-dated

Walk back through the session. For every task, decision or open thread that
was mentioned, worked on, or ruled on:

- **Closed** — set `status` to `done` / `decided` / `closed`. For session
  events, set `closed_at = now()` and `resolved_in` to this session's label.
  Add one line of evidence to the notes where it fits.
- **Re-dated** — set a new `next_check_at` **and** confirm the `owner`. A
  re-date without a reason is not allowed; put the reason in the notes.

A ruling that *starts* something is never closed on creation. The ruling
gets a closed `ruling` event; the work it started gets its own open row.

## 2. Record what happened — one line each

INSERT into `session_events`, one row per item, with `refs` pointing at
anything checkable (a link, a file path, a row id):

| kind        | What it is                                  | Status   |
|-------------|---------------------------------------------|----------|
| `shipped`   | something now exists or works that did not  | closed   |
| `ruling`    | a decision the founder made                 | closed   |
| `learning`  | something true learned the hard way         | closed   |
| `open_thread` | started and not finished                  | open     |
| `question`  | something only the founder can answer       | open     |

One line each. If a line needs a paragraph, it belongs in a task's notes.

## 3. Write the handoff

INSERT one `session_handoffs` row. Four fields are required and the database
rejects the row if any is empty:

- **`measured`** — what was checked live this session. Facts only.
- **`ruled`** — decisions made, or "none".
- **`in_flight`** — what is started and unfinished, and where it stopped.
- **`do_not`** — traps: things the next session must not do or repeat.

Optional: **`hypothesised`** — believed but not verified. Keep it separate
from `measured`. **`notes_markdown`** — deltas only, 6000 characters max.
Its first line names the doctrine version, for example `doctrine: v2`.

## 4. Loop 2 scan → file recs, never prose

Ask: what did we do by hand this session that we have done before? For each
answer, add a task: `Automate: <the step>`, owner `system`, status `inbox`,
with where it was seen and a proposed approach in the notes. If the answer
is "nothing", that is fine; write nothing.

Doctrine: if this session taught a new law, add it per the amendment rule and
record a `learning` event.

## 5. Check the standing rule

**No open item without an owner and a `next_check_at`.** The last query in
`scripts/close.sql` must return zero rows before the founder commits. The
insert trigger fills a 7-day default; a deliberate date is better.

---

## Hand it over

Give the founder the filled-in SQL in one block, with a three-line summary
above it: what closed, what was re-dated, what is in flight. Running it is a
create and an update, so it is the founder's action, not yours — unless the
founder has graduated "run the close" to automatic in the Doctrine.
