Persona Sections

Overview

A persona today is one block of text (personas → persona_contents.prompt), and everything in it reaches the model from the first message. There is a table for linking lorebooks to a persona (persona_lorebook_bindings) and the lorebook read already uses it, but nothing writes to it yet. That fits what anyone can see about you. It does not fit what the story hasn't reached yet: your apartment before anyone has been there, a scar under your sleeve, the job you don't talk about. Writers work around this by keeping copies: "Mira (start)", "Mira (after the flat)", "Mira (after the reveal)". The description column exists for exactly that ("for version management"). Every copy drifts from the others, and each change has to be made in all of them.

Persona sections replace the copies. A persona has a base, which is what everyone knows and is always on, plus any number of sections, each with its own title and text. The conversation decides which sections are switched on. When the story reaches your home, you switch on Home and the model learns about it from that point. A section can also bring its own lorebooks (Home brings the apartment lorebook with one entry per room), and those lorebooks are in play only while the section is on.

Design Goals

  1. One persona, many stories. The same persona is in three conversations at three different points in each story. So which sections are on is a property of the conversation, never of the persona.
  2. Unrevealed means unsent. A section that is off never reaches any model call: not the story prompt, not the tracker or journal eval, not summarization, not the hybrid planner. This is not a soft hint.
  3. One point of assembly. Every consumer already reads the persona through one path (fn_get_conversation_persona → IPipelineContext.GetPersonaAsync()). Section filtering happens there, so no consumer can forget it.
  4. Nothing existing changes. A persona with no sections behaves exactly as it does today. The base is the current prompt, so there is no data migration.
  5. Revealed by the story, not by a keyword. A keyword lorebook entry fires when something is mentioned ("let's go to your place"). A section is in play when the story has reached it. These are different concepts, and sections don't replace keyword entries. Inside an active section's lorebooks, keywords work as usual.

Non-Goals

Design

Where the state lives, and why not conversation settings

The switch appears among the conversation's settings: in the chat's settings drawer, next to the persona picker (the Who drawer today). It is not stored in web_conversation_settings. That table is the settings substrate's key/value override of default_settings keys (one scalar per key, looked up through fn_get_web_settings). Section state is a set of references to persona rows. It needs a foreign key so that deleting a section cleans up after itself, it has to be copied when a conversation is branched, and it has to be joined in SQL by both the persona read and the lorebook read. Storing it as a JSON value in the settings table would lose all three. So the UI home is the conversation's settings, and storage is a dedicated table.

Data model

-- The base stays where it is: persona_contents.prompt. Sections are the additions.
CREATE TABLE IF NOT EXISTS persona_sections (
    id SERIAL PRIMARY KEY,
    uuid UUID NOT NULL DEFAULT gen_random_uuid(),
    persona_id INTEGER NOT NULL REFERENCES personas(id) ON DELETE CASCADE,
    title VARCHAR(80) NOT NULL,
    body TEXT NOT NULL DEFAULT '',
    sort_order INTEGER NOT NULL DEFAULT 0,          -- MAX+1 on insert
    active_by_default BOOLEAN NOT NULL DEFAULT FALSE,
    character_count INTEGER NOT NULL DEFAULT 0,
    -- Phase 2 hook, unused in v1: a tracker condition that switches the section on.
    reveal_condition JSONB DEFAULT NULL,
    created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
);

-- Per-conversation override. No row = the section's active_by_default.
CREATE TABLE IF NOT EXISTS conversation_persona_section_states (
    conversation_id INTEGER NOT NULL REFERENCES web_conversations(id) ON DELETE CASCADE,
    section_id INTEGER NOT NULL REFERENCES persona_sections(id) ON DELETE CASCADE,
    active BOOLEAN NOT NULL,
    updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (conversation_id, section_id)
);

-- A lorebook can belong to one section. NULL = the base = always in play (today's behavior).
ALTER TABLE persona_lorebook_bindings
    ADD COLUMN IF NOT EXISTS section_id INTEGER REFERENCES persona_sections(id) ON DELETE CASCADE;

ON DELETE CASCADE on the binding is deliberate. SET NULL would turn a deleted section's lorebooks into base lorebooks, which means always on and exactly the leak this feature prevents.

Switching a conversation to a different persona leaves the old persona's state rows in place. They are ignored while another persona is attached and apply again if the writer switches back.

Assembly

API (ServerAPI)

Route Purpose
GET/POST /api/personas/{uuid}/sections list / create (owner only)
PATCH/DELETE /api/personas/{uuid}/sections/{sectionUuid} edit (three-state semantics) / delete
PUT /api/personas/{uuid}/sections/order reorder
GET /api/conversations/{id}/persona-sections the attached persona's sections, each with its effective state and token estimate
PATCH /api/conversations/{id}/persona-sections { sectionUuid: bool, … }: switch sections on or off, surgical

Binding lorebooks to a persona has no write path yet. persona_lorebook_bindings has a reader (fn_get_conversation_lorebook_ids) but no writer anywhere. It was decided on 2026-07-20 that the binding is wanted and deferred until it ships "with its write endpoint + Vault persona editor section together" (docs-internal/architecture/content/ENTITY_LINKS.md §3.2). This feature is that ship: slice 2 adds GET/PUT /api/personas/{uuid}/lorebooks (the full set, each entry { lorebookUuid, sectionUuid | null }, lorebooks the caller can use only). It also opts persona into the References panel, whose persona arm in fn_get_entity_references (90_entity_references.sql) is already written and waits only for this.

UI (chatConsole)

Implementation Plan (sliced)

# Slice Where State
1 Schema + assembly. Both tables, the filtered fn_get_conversation_persona, Discord default-only read, branch copy, the section CRUD and conversation-state endpoints, tests (DB: assembly and defaults. API: ownership, surgical PATCH) backend, any time ✅ (M4; sections ride the persona save, the card is a new fn_get_conversation_persona_card, Discord reads no persona)
2 Persona lorebooks, base and per section. The first writer of persona_lorebook_bindings (GET/PUT /api/personas/{uuid}/lorebooks), section_id on the binding, the filtered lorebook read, persona added to the References panel (ENTITY_LINKS §3.2: ships together with the editor, so backend and slice 3 land in the same change) backend + slice 3 ✅ per section (M5, through the persona save); base lorebooks and the References panel arm not built
3 Persona editor with sections chatConsole, at the stop that rebuilds personas ✅ (M4 + M5)
4 The in-chat switch panel chatConsole, at the Story surface step (10+) ✅ (M4, the story's persona panel)
5 Revealed by trackers (Phase 2): reveal_condition set in the editor. When the tracker eval sees the condition met, the section switches on and a notice appears in chat later 📋 vision

Slice 1 can ship before any chatConsole page exists: with no UI, every persona has only a base and nothing changes. Slice 2's write endpoint waits for the editor (slice 3), per the ENTITY_LINKS decision. Until then the References panel shows no persona arm.

Open Questions

For the owner:

Mine to decide at build time: the section header format in the assembled card; whether a switch toggled while a reply is streaming applies to that reply (proposed: no, it applies to the next one).

Acceptance Criteria

The feature is not done until every box below is verified ✅ against the running product. Boxes amended by the as-built record (PERSONA_SURFACE.md) say so inline; none was re-driven in the 2026-10-29 status pass.

User use cases: satisfiable + accessible (verify by driving the UI, not the code):

Behavior:

Invariants that must stay true:

Edges: