Prompt Presets — Reusable, Shareable Prompt Snippets
What we are actually solving
Three unrelated-looking feature requests turn out to be the same shape:
- Custom Instructions is a single per-conversation free-text field today — mode-independent,
appended near the end of the system prompt, before the response-pacing/target-words directives
(
PromptContextManager.AppendCustomInstructionsAsync,server/EchoOfDreams.Core/Pipeline/Providers/PromptContextManager.cs:278-311). There's no way to save more than one, name them, or reuse a favorite across conversations. - Summarization is currently owned by Mode (
prompt_mode_contents.summarize_messages_prompt/summarize_summaries_prompt) and — per Hybrid Pipeline §3 — is about to move to being owned by the beat mode specifically. The dev wants to go further: decouple it from Mode entirely so a user can author/select their own summarization behavior independent of whatever Mode they're chatting in. - Model Profile Flavors (Document Mode Editor §Model-selected base prompts and flavor overlays,
unbuilt) are already spec'd as "one optional, user-toggleable, profile-owned keyless System
sub_prompt" with an explicit import-as-private-clone mechanism for pulling in accessible prompt text from elsewhere.
All three are the same underlying storage need: a named, reusable block of instruction text, selectable independent of the thing that's using it. But they split hard on one axis that matters a lot downstream — who writes the content:
| Consumer | Authored by | Scope | Distribution |
|---|---|---|---|
| Custom Instructions | The end user controls it — always, no exceptions. (A package may seed the initial text — moderated at package publish, user-owned from creation on; see the decided item below) | Private by default, personal preference | Affects only that user's own conversations (unless explicitly shared peer-to-peer) |
| Summarization preset | The end user, for themselves | Private by default, personal preference | Same — self-scoped |
| Flavor overlay | The creator, as part of building their Model Profile | Profile-owned, one of several toggleable style layers | Ships to every reader of every Package/conversation that resolves that creator's Model Profile |
Custom Instructions and Summarization are the same case as each other: a user writing a note to the
model about themselves. (Custom Instructions here means standing rules for the whole RP — style,
POV, limits. The steering use case that field also absorbs today — "plot direction for the next few
messages" — is deliberately split out into its own sibling field, Author's Notes,
which is not a preset consumer; the split purifies what a Custom Instructions preset is for.)
Flavor is a different case wearing similar clothes: a creator writing style/tone
instructions that ride along with their published work, at audience scale — much closer in kind to Mode
or Character content than to a personal preset. The shared substrate below (sub_prompts) is still the
right storage/reuse mechanism for all three, but the moderation weight and sharing model must not be
unified across this line — see Moderation model below.
Decided (dev, this implementation): package-locked Custom Instructions are retired. Custom Instructions is purely user-controlled, always — a Package can still seed an initial value, but can no longer lock it. (An earlier draft overstated this as "a Package no longer supplies or locks one" — half wrong, and it contradicted the precedence rule this doc itself states later. Corrected on review, 2026-07-31.) The precise split:
- Retired: the lock.
ConversationsEndpoints.cs:850-853("Enforce package locks... reject locked changes") — shipped 2026-07-22, commit4fff5326d. The conversation owner can always set/change/wipe their Custom Instructions, regardless of where the conversation came from. - Kept: the seed.
fn_create_conversation_from_packagestill materializes the package'scustom_instructionsas the conversation's starting value (47_package_functions.sql:458-463) — an ordinary, detached, locally-owned text the moment it lands, indistinguishable from text the user typed. This is deliberate (the precedence rule builds on it), and it is not an unmoderated third authorship case: packagecustom_instructionsis already swept by the package publish checks, prompts area, verbatim (32_run_content_checks.sql:504-563—fn_run_keyword_check(v_rec.custom_instructions, 2)), because it's injected into the LLM context at runtime.
So "user-driven" means control, not "no creator ever typed the first draft": the creator seeds, moderation screens the seed at package publish, and the user owns it from conversation creation onward. No locked-value path survives, which is the simplification that matters for this design.
Scope note — this retires the behavior, not necessarily the column. instructions_locked is one
member of a package-wide lock-flag family (CharacterLocked/ModeLocked/LorebooksLocked/InstructionsLocked)
threaded through 24 files — agent authoring tools, changelog triggers, browse listings, package
CRUD — not narrowly scoped to this one check. What's in scope here is removing its enforcement effect on
Custom Instructions; whether the column/API field itself gets cleaned up package-wide is a separate,
larger concern this doc doesn't take on. See Legacy migration
for what happens to conversations that currently have a locked value.
The core idea — reuse sub_prompts, don't invent a new prompt-content storage mechanism
sub_prompts already has almost the whole shape (database/v1/04_tables_prompts.sql:119-243):
sub_prompts—name,provider_key,role,is_public,published_at,character_count,created_by_user_id,uuid. Content lives insub_prompt_contents(large text, split out).prompt_mode_sub_prompt_links— the N:M junction the schema already supports. Correction: this is schema-capable, not a proven live pattern — checked how it's actually exercised today and it isn't. Creating a sub-prompt always inserts a new row (CreatorModeEndpoints.cs:446-453,UpsertSubPromptAsync(null, …)), and copying a Mode clones every sub-prompt into brand-new rows rather than re-linking the existing ones (CreatorModeEndpoints.cs:639-654). So today, in practice, it's a 1:1 relationship that happens to sit on N:M-capable schema — no current product flow actually fans onesub_promptsrow out to multiple parents. That's still a reasonable substrate to build real reuse on top of; it just isn't evidence that reuse is already proven in production, and shouldn't be cited as if it were.expansion_versiononsub_prompts/editor_kindonprompt_modes(Document Mode Editor §Two independent discriminators) — not built yet (that whole doc is "Planned / design — implementation-ready. No code yet."; grepped the DB forexpansion_version, no matches), but it's the pattern that same design already commits to for "same row, different authoring/resolution contract." Worth following the same shape rather than inventing a second discriminator scheme, since both would ship into the same unbuilt-but-spec'd neighborhood — just don't cite it as existing convention it isn't yet.
What's missing is the ability for a sub_prompts row to be selected standalone — referenced
directly by id from Custom Instructions settings — without being linked into a Mode's assembly at all.
Today the only two ways a sub-prompt's content reaches the model are (a) via prompt_mode_sub_prompt_links
into a Mode, or (b) — for Flavors, once built — a profile-owned private clone. Neither fits "pick one
saved block of text and use it verbatim, standalone."
Correction: this framing only holds for Custom Instructions. Summarization needs a small new
aggregate entity on top of this substrate, not a third standalone sub_prompts row — see
What's new below for why, and
Summarization needs its own research pass for the reasoning
that forces it. The header above is scoped precisely: don't invent a new way to store prompt text (that
part, sub_prompt_contents, gets reused everywhere); a small aggregate that owns two content rows plus
a field schema is still new structure, just not new text storage.
What's new
- A
purposediscriminator onsub_prompts, scoped to Custom Instructions only — a single'custom_instructions'value, distinguishing it from the existing "mode-section" row (content that fills a{content}slot inside an assembled prompt, gated byprovider_key; no purpose tag, unchanged). Forcing a standalone preset throughprovider_keysemantics would be a category error —provider_keydrives which content provider fills the slot; a standalone preset has no slot to fill. A typed discriminator (following the shapeexpansion_versionalready commits to) keeps the one table honest about the two contracts sharing it. Correction: this is Custom Instructions' shape only, not Summarization's — see item 2. An earlier draft of this doc gave Summarization its own'summarize_messages'/'summarize_summaries'purpose values here, each independently selectable by id. That directly contradicts the "one versioned aggregate" decision in Summarization needs its own research pass — a singlesub_promptsrow can't own two prompts plus a field schema, and two independently-referenced rows let a user pick a mismatched pair. Fixed below; don't reintroduce the split purpose values. (Flavor still gets nopurposevalue at all, for the separate reason already covered: per Document Mode Editor §Model-selected base prompts and flavor overlays, "There is nois_bundlepseudo-type and no intrinsicsub_prompts.is_flavor: Flavor meaning/default/order belongs to its profile link" — Flavor identity lives on the profile-link row, never onsub_prompts.) - Two different reference shapes for the two consumers, not one uniform pattern (both live FKs to a
row the user owns — see
Mutation semantics):
- Custom Instructions gets a nullable
custom_instructions_preset_idFK on the conversation, pointing at apurpose='custom_instructions'sub_promptsrow the user owns. Set → the preset's text is live and edits propagate. NULL → the existingcustom_instructions_idlocal-text row applies, exactly as today. Editing instructions inside a conversation clears the FK and detaches to local text. No mode link required — this is genuinely one block of text, the simple case. - Summarization gets its own small aggregate table (call it
summarization_presets: id, uuid,created_by_user_id,name,is_public/published_atmirroringsub_prompts' sharing shape, plus two ownedsub_prompt_contentsrows — reusing that table purely as raw large-text storage, not as independently-addressablesub_promptsrows — for the messages-prompt and rollup-prompt bodies, and an owned field-schema definition, likely a child table mirroring Trackers' typed-field-definition shape). A consumer applies the aggregate as a unit, never a child content row on its own — that's what makes "both prompts agree on the schema" enforceable at all. This is the new-but-narrow piece: not new text storage (stillsub_prompt_contents), but a new small entity that owns two of them plus a schema, because Summarization's two prompts can't be independently swapped without breaking the contract between them. Whether Summarization attaches live like Custom Instructions or pins its schema at attach time is deliberately left to slice 3 — see the Summarization lean; it has a schema-stability constraint Custom Instructions doesn't. - Flavor keeps its existing profile-owned clone mechanism per the Document Mode Editor design — the same "clone into your own scope, then own it" rule the import path uses, one layer over.
- The invariant across all three: you only ever reference a row you own. Sharing works by cloning into your library at import, never by pointing at someone else's row — see Mutation semantics.
- Custom Instructions gets a nullable
- A lightweight, non-blocking moderation trigger on publish, for user-authored presets only — see below. This is the piece that makes "let users share their own Custom Instructions/Summarization presets with each other" viable without building a second full review pipeline. It is not the moderation story for Flavor content — that's a separate, heavier problem (see below).
- A structured field-builder for Summarization presets, so a non-technical user names the fields they want preserved instead of hand-writing a JSON-format instruction. See Summarization needs its own research pass below — this is the biggest open unknown in the whole doc.
- A shared "pick a saved prompt" UI, reusable across the Custom Instructions picker, the
Summarization preset picker, and — per the Flavor overlay's existing "import accessible prompt text"
design — potentially the Flavor import picker too, so there's one place a user browses their private
library and public shared presets, not three bespoke pickers. Correction: this belongs in slice 1,
not deferred to a later "unify" slice. This doc names two consumers (Custom Instructions,
Summarization) up front — the repo's own rule-of-two convention (root
CLAUDE.md§On Reuse: "As soon as a block of markup gains a second consumer (or you can see it will gain one in this same change), extract it into a shared component. Do not copy-paste it 'for now'") says build the shared picker at first implementation, not bespoke-then-unify. An earlier draft of this doc deferred it to slice 4, which is exactly the pattern that rule exists to prevent. - A user-level default preset for Custom Instructions, auto-applied to new conversations the same
way a default persona already is — a column-for-column clone of the existing
Persona.DefaultIdmechanism (setting key, ownership-enforcing resolver,COALESCEin the same INSERTs), not a new pattern. Custom Instructions only; Summarization and Flavor get no default in this slice. See A user-level default preset.
Mutation semantics — decided: live FK to a row you own; import clones first
Decided (dev, 2026-07-25): a conversation references its preset by FK, live — edits propagate. The
invariant that makes that safe is you only ever reference a row you own: importing someone else's
public preset clones it into your own library first, and from then on it's your row. No version counter,
no revision history — the only schema additions to sub_prompts are the purpose discriminator and
is_deleted.
This mirrors the default-persona mechanism exactly (web_conversations.user_persona_id is a live FK to
a row the same user owns), which is the working precedent for "the user's own reusable thing, attached
to the user's own conversation." A preset is the same shape, so it gets the same treatment.
The three rules
- Attach a preset → live FK. Editing the preset updates every conversation still linked to it. That's the point of "my preset." Attaching over existing local text replaces it — the local row is cleared so the two columns are never both authoritative (the precedence section requires "both set" to be ruled out; this is where it's ruled out for the attach path).
- Edit the instructions inside a conversation → it detaches into that conversation's own local text
(the existing
conversation_custom_instructionsrow), and the preset FK is cleared. A local edit is never a silent edit of the preset — that would rewrite conversations the user wasn't looking at. This is why both columns coexist:custom_instructions_preset_idfor the linked case,custom_instructions_idfor ad-hoc typed text, and ad-hoc typed text stays a first-class case forever. - Import someone else's preset → clone into your library first. You never hold an FK to a row you don't own, so a shared preset's author can never reach into your conversations, and unpublishing theirs can't break yours. This is already the mechanism Flavor specs (import-as-private-clone) — consistent, not novel.
What this costs, stated plainly
One real addition, and it's work slice 2 needs anyway:
The 5,000-character cap and the vector injection check must additionally run at preset save/edit —
they do NOT leave conversation-save. They currently run on the text at conversation-save
(ConversationsEndpoints.cs:915-927), and they stay there: the local/detached text path is first-class
forever (rule 2) and still flows through it. But with a live FK the preset's text reaches the prompt
without ever passing through that path, so both checks must also run where preset text is authored — at
preset write — and re-run on every edit. That re-run requirement is not extra scope: it's the same
moderation re-check-on-edit requirement
slice 2 already carries, so the two share one transactional gateway rather than being two jobs.
Everything else is small or unchanged:
| Concern | Status under a live FK |
|---|---|
| Context Budget | Two-line change — chase the preset instead of the local row. Structurally identical to the persona budget line that already ships (ConversationBrowseRepository.cs:419-425) |
| Legacy rows | Unchanged. Existing rows have a NULL preset FK, so they're just the ad-hoc-typed case, which stays first-class. Still no migration |
| Branching | One line — fn_branch_conversation copies the FK alongside the persona and text it already copies (the column is new, the behavior isn't) |
| Deletion | is_deleted keeps the row, so linked conversations keep resolving; the preset just leaves the library |
| Mid-turn preset edit | Same exposure persona already has today, self-inflicted and tiny. Not treated as a defect there; not one here |
Where is_deleted still earns its place
Soft-delete on sub_prompts is the one schema addition, and it's purely additive — verified, not
assumed: there is no DELETE FROM sub_prompts anywhere in the schema. Only link rows are ever
deleted (fn_delete_mode_sub_prompt_links, 08_mode_migration_functions.sql:483); the sub_prompts
row simply orphans. So is_deleted retrofits no existing delete path, and the ~10 existing readers
(FROM sub_prompts / JOIN sub_prompts — mode assembly, content checks, entity stats) are unaffected
as long as the new soft-delete path is scoped to standalone preset rows. It also matches the convention
already set one function over: fn_delete_prompt_mode (08_mode_migration_functions.sql:495) is a soft
delete. sub_prompts is currently the odd one out.
Soft-delete is also what makes the live FK safe on the delete path, and the contract is an
asymmetry — state both halves so both get built: existing links keep resolving (the row survives;
a linked conversation's instructions don't vanish, the preset just shows as removed from the library),
while every forward-looking selection path rejects the row — the library list, the attach-time
read-authz check, and the default resolver all filter NOT is_deleted. Miss the second half and a
"deleted" preset silently keeps spreading to every new conversation through the user's default —
precisely the surprise soft-delete exists to prevent. Hard-delete would have forced either a fan-out
write or a dangling FK.
Lean for Summarization (slice 3, not decided here)
Summarization is the one place the copy argument may still be right, and for a reason that doesn't apply to Custom Instructions: the schema-drift-across-rollups problem wants a conversation's field schema to be stable for the conversation's whole life, which a live FK doesn't give. Pinning or copying the schema at attach time would. Noting the lean, not deciding it — Summarization has its own research pass and its own aggregate shape, and this doc shouldn't pre-empt it. The important part is that Custom Instructions and Summarization are allowed to differ here; they have genuinely different constraints.
A real authorization gap this surfaces, not a hypothetical one
Promoted to its own section: it was a subsection of Mutation semantics when both were open. Now that mutation is decided and this isn't, burying the one remaining hard blocker under a "decided" heading would hide it.
Checked the SQL function that actually mutates a sub_prompts row —
fn_upsert_sub_prompt/08_mode_migration_functions.sql:131-149 — and it has no ownership check at
all. The update branch (UPDATE sub_prompt_contents ... WHERE id = v_existing_content_id, then
UPDATE sub_prompts SET ... WHERE id = p_sub_prompt_id) never compares created_by_user_id against
the calling user, even though the function receives p_user_id as a parameter. This is safe today
only because every current caller checks parent access first — CreatorModeEndpoints.cs:430-432
(RequireEntityAccess(context, "mode", modeId, a => a.can_edit, …)) gates the Mode before this function
is ever reached, so the sub-prompt id is always reached indirectly through an already-authorized parent.
A standalone preset endpoint (Custom Instructions/Summarization, addressed directly by sub_prompts.id,
no Mode in the loop) removes that indirection. If it calls the same SQL function directly, nothing in
the function stops user A from editing user B's preset by guessing or discovering its id — the parent
gate that made this safe simply isn't there anymore. Slice 1 needs its own explicit ownership check
(created_by_user_id = p_user_id, or an app-layer check before calling in) — either added to
fn_upsert_sub_prompt itself or as a new function/endpoint-level guard for the standalone path. This
isn't optional hardening; the current function is unsafe to call directly without it.
This hole is independent of the mutation decision. It's about editing a preset row you don't own, an operation that exists however the preset's content later reaches a conversation. Still a slice-1 blocker, and the hardest-edged item on the list because it's a real hole rather than a design preference.
Existing Custom Instructions also has a full validation contract, and under a live FK it doesn't simply
carry over — part of it has to move. Today: ownership checked before any compute happens
(ConversationsEndpoints.cs:903-913, explicitly ordered this way — a non-owner 403s before triggering an
embedding charge or learning package-lock state), a hard 5,000-character limit (:915-917), and a
vector-similarity injection-pattern check against the text (:919-927).
- Ownership-before-compute stays exactly where it is — it guards the conversation, which still has its own local-text path.
- The 5,000-char cap and the injection check gain a second site: preset save/edit. They stay on conversation-save (the local/detached text path still needs them) and additionally run where preset text is authored, re-running on every edit — with a live FK the preset's text reaches the prompt without passing through conversation-save, so a preset-side gap would be uncovered by the existing checks. These are purpose-specific invariants on this text (it lands in a system prompt) — the lightweight report-style moderation check does not substitute for them, it runs alongside them through the same gateway.
Attaching a preset also needs its own read-authz check, separate from ownership-before-mutation:
- The id actually has the expected
purpose(or is the right kind ofsummarization_presetsaggregate) — a consumer blindly trusting an id could be handed the wrong shape of row. - The row is not soft-deleted. Attach and default-selection reject
is_deletedrows — "removed from my library" must mean removed from all future selection, while conversations already linked keep resolving (the deliberate asymmetry in theis_deletedsection above). Without this condition a deleted preset silently keeps spreading to new conversations via the default. - The caller owns the row. Under the import-clones-first rule this is stricter than "readable": you never attach someone else's row at all, so "public" is a reason to offer an import, never a reason to accept an FK.
- A private preset can't be probed by guessing/enumerating ids — existence of a row you don't own must
not be confirmable by an attach attempt, mirroring the existing not-found-collapses-with-forbidden
pattern Custom Instructions already uses (
ConversationsEndpoints.cs:908-913).
Two things an earlier draft listed here are resolved by the import-clones-first rule rather than left open:
- Unpublish/delete of a preset that's attached somewhere — can only ever be your own preset, and
is_deletedkeeps the row, so attached conversations keep resolving. An author unpublishing their public preset can't affect anyone, because nobody holds an FK to it. - Turn-accept plan freeze — a live FK does technically expose a mid-turn edit window, but it is the
same exposure
user_persona_idalready carries today and is not treated as a defect there. Folding the preset into the Document Mode Editor plan-freeze is available if it ever matters; it isn't a slice-1 blocker, and doing it for presets while leaving persona out would be incoherent.
Substrate boundaries the discriminator alone doesn't enforce
Raised on external review (2026-07-31), and correct: purpose='custom_instructions' is a label, and
nothing about a label stops a preset row from being linked into a Mode via
prompt_mode_sub_prompt_links — the two contracts sharing the table need write-side enforcement, not
just read-side purpose checks:
- Parentage: a
purpose='custom_instructions'row must be rejected by the mode-link writer (and a mode-section row rejected by the attach path — the read-authz purpose match above covers that half). Enforcement shape — DB trigger/CHECK vs. the single-gateway invariant — is a slice-1 call; the gateway is where the moderation model already needs every write to flow anyway. - Shape: preset rows carry
provider_key IS NULL(no slot to fill) and a fixed role — assert it at the writer, don't rely on the UI never sending otherwise. - Ownership across account lifecycle: the repo already has atomic entity transfer machinery
(WP-20). A transferred conversation whose
custom_instructions_preset_idpoints at a preset the recipient doesn't own would violate the you-only-reference-a-row-you-own invariant the moment it lands. Transfer must therefore detach to local text (snapshot the current content, clear the FK) or clone the preset to the recipient — lean: detach, it's the same semantics as a local edit and needs no new mechanism. Account deletion gets the same treatment for any surviving referents.
Legacy migration — no longer a question
There is no migration. An existing conversation_custom_instructions row is already exactly what
the detached / ad-hoc case
looks like — literal text in the instructions column, with a NULL preset FK. That's a valid
post-feature state, not a legacy state needing conversion: it's simply a conversation whose instructions
were typed rather than attached from a preset, which stays a first-class case forever (it's the same
state a user lands in the moment they edit a preset-linked conversation locally). Every existing row
keeps rendering, keeps being editable, and needs no backfill, no flag, and no dual-read path.
For the record, the three cases that exist in that bare table today
(07_tables_conversations.sql:13-22 — id, instructions, created_at, updated_at; no owner, no
source flag) and where each lands:
- Ordinary user-typed Custom Instructions → unchanged, indistinguishable from a post-feature hand-typed value.
- A package-authored
instructions_lockedvalue the reader never wrote → already handled by the package-lock retirement (shipped 2026-07-22, commit4fff5326d): the value simply stopped being locked and became an ordinary editable starting value for the conversation's owner. Collapses into case 1. - A branching snapshot (
38_branch_conversation.sql:159-164copies the text into a fresh row with no back-reference) → unchanged. A branch of a preset-linked conversation should carry the FK across the same way it carries persona and text, so the branch stays linked too — one line to add alongside the existing copy.
The one genuinely optional nicety, explicitly not required: offering a user a "save this as a preset" action on a conversation that already has text. That's an additive UI affordance whenever someone wants it, not a migration.
A user-level default preset — mirror the persona mechanism verbatim
Decided (dev, 2026-07-25): a user can mark one Custom Instructions preset as their default, applied to new conversations exactly the way a default persona already is. Custom Instructions only — Summarization and Flavor get no default in this slice.
This is deliberately not a new pattern. The default-persona mechanism already exists, is already applied server-side in both conversation-create paths, and already handles the stale/not-owned/malformed cases — so this is a clone of a working thing, not a design. Its four parts and their Custom Instructions counterparts:
| Part | Persona (existing) | Custom Instructions (new) |
|---|---|---|
| Storage | user_settings row, key Persona.DefaultId, value = id as a string (SettingsKeys.cs:1145). No schema change — user_settings is generic KV |
CustomInstructions.DefaultPresetId, same shape, pointing at a purpose='custom_instructions' sub_prompts row |
| Resolver | fn_get_default_persona_id(user_id) — STABLE SQL, ownership enforced in the JOIN, returns NULL for unset / stale / not-owned / non-numeric (11_conversation_migration_functions.sql:216-227) |
fn_get_default_custom_instructions_preset_id(user_id) — same shape, same return kind (an id), joined against sub_prompts with purpose='custom_instructions' AND NOT is_deleted — a preset removed from the library must stop attaching to new conversations even while existing links keep resolving it (the soft-delete asymmetry, below) |
| Application | COALESCE(p_persona_id, fn_get_default_persona_id(…)) in the INSERT (:387); package path calls it bare since package start has no persona pick (47_package_functions.sql:483) |
non-package path: the same COALESCE(explicit, default) on the new custom_instructions_preset_id column. Package path: guarded, not bare — the default resolver runs only when the package supplies no custom_instructions text; a bare COALESCE there would set both the package's local text and the default FK, the exact both-set state the precedence rule forbids |
| Surface | GET/PUT/DELETE /api/personas/default (PersonasEndpoints.cs:363-498) + a per-row "set as default" action with the default pinned to the top of the list (PersonasTab.tsx:148) |
the same three routes and the same affordance on the preset library |
It's a column-for-column clone (with one guard the persona version doesn't need)
Because the preset is a live FK like the persona is, the application step on the non-package path is
literally the same expression on a different column — COALESCE(explicit, fn_get_default_…(p_user_id))
in the same INSERT that already resolves the persona default. No new insert, no new row, no text
handling. The package path is the one divergence from a pure clone: there the default is wrapped in
the package-text guard (apply only when the package supplies no custom_instructions — see the
Application row above and Precedence), a condition the
persona default never needed because packages don't seed personas.
That's a simplification over what an earlier draft of this section described. Under copy-on-apply the
default had to materialize a conversation_custom_instructions row at creation, and the note here was
that fn_create_conversation_from_package already had a template for exactly that
(47_package_functions.sql:458-463 + :485). That template is no longer needed for the default path —
but it remains the reference for how the package supplies its own instruction text, which is still how
precedence gets resolved below.
It really is the same mechanism, all the way down
web_conversations.user_persona_id is a live FK to a row the same user owns; the preset FK is a live FK
to a row the same user owns. So the resolver returns an id, not text, and the "set as default"
affordance can behave identically in both places without teaching a wrong expectation — editing your
default persona and editing your default preset both propagate to conversations still linked to them.
(An earlier draft of this section had the resolver return text and warned about the resulting asymmetry;
that asymmetry is gone along with copy-on-apply.)
One difference remains, and it's a UI concern rather than a mechanism one: a conversation can detach from its preset by editing the instructions locally (rule 2 above), which has no persona analogue. The default only ever applies at creation, so detaching later is unaffected by it — but the picker should make "linked to Terse prose" versus "edited locally" visible, or a user will wonder why their preset edit didn't reach a particular chat.
Precedence, the one actual design question
Only the package path has a conflict, because it already supplies its own custom_instructions as
text when non-empty (47_package_functions.sql:459-463) while the user default supplies a preset
FK — the two sit in different columns, so "both set" is representable and has to be ruled out
deliberately rather than left to whichever runs last.
Decided: the package's text wins when it supplies one — the conversation starts in the detached/local
state with the package's text and a NULL preset FK. The user's default preset applies only when the
package supplies nothing. That mirrors COALESCE(explicit, default), and it's safe because the lock
was retired: the package's value is now just a better starting point the reader can freely edit, wipe, or
replace by attaching one of their own presets, not something they're stuck with.
Carve-out to copy deliberately: branching must not re-apply the default
fn_get_default_persona_id's own comment spells out why the branch path deliberately skips it: "a
branch copies the parent's persona including NULL — a user who detached their persona must not get the
default re-applied" (11_conversation_migration_functions.sql:206-208). The same must hold here.
Branching already copies instruction text verbatim (38_branch_conversation.sql:169), so it holds for
free today — record it as intentional so a later change doesn't "helpfully" add default resolution to
the branch path.
Two registration points a naive implementation will miss
Both found by grepping the persona key rather than assumed, and both fail loudly rather than silently — but only if you know to look:
89_enforce_setting_write_scopes.sql:13— a write-scope registry:('Persona.DefaultId', ARRAY['user'], 'Fixed-key default-persona endpoint.'). The new key needs its own row or writes to it are rejected.SettingsSeedingTests.cs:35— an explicit allowlist of keys that are deliberately not seeded intodefault_settings("Persona.DefaultId", // per-user). The new key must be added there or that test fails. This is the enforced form of the "a key only lists if it has adefault_settingsrow" rule; a per-user fixed-key setting is the sanctioned exception.
Moderation model — differs by who wrote it
The authorship split above is the reason this section can't be one policy. Traced the existing mechanism precisely rather than guessing:
- Today, a sub-prompt is only ever moderated as a side effect of being linked into a Mode that itself
goes through
publish_requests. The keyword step (database/v1/functions/32_run_content_checks.sql:266-330, mode-check block) joinsprompt_mode_sub_prompt_links→sub_prompts→sub_prompt_contentsand keyword-checks every linked row (field_type='sub_prompt'). The AI classifier/verifier steps do the same viaPublishRequestFieldLoader.LoadEntityFieldsAsync(EntityType.Mode, …)→AdminGetModeSubPromptsAsync. There is no independent moderation identity for a sub-prompt outside that join. sub_prompts.is_public/published_atare vestigial — the columns exist but nothing in the codebase ever setsis_public = TRUE.EntityRegistry.cs:198-200has aPromptentry, but it aliasesEntityType.Mode(a route/display shim, not an independent type) and defaultsSupportsPublishing: false— it never participates in the publish/moderation pipeline the way Character/Lorebook/Mode do.
User-authored (Custom Instructions, Summarization) — lightweight, report-style
The dev's proposed model: publish immediately, check runs, result is "report style," not a gate.
This deliberately diverges from Character/Lorebook/Mode, which block public visibility behind a
human-approved publish_requests row (Pending → Approved/Rejected). A user's own personal preset,
self-scoped or shared peer-to-peer, is a much smaller attack surface than a full character or world —
so the proposal is: flip is_public = TRUE immediately, run the same proven keyword check
(fn_run_keyword_check(..., 2) — the "prompts" area, already used for mode sub-prompts) inline,
synchronously, in the same transaction — no publish_requests row, no pg_notify, no background
worker, no pending state. If it flags, the preset stays live but a report is left for admin
visibility, matching the platform's existing "flag, don't block generation" posture rather than
inventing a new blocking gate. The closest existing UX precedent for "runs a check, doesn't gate" is
ContentPreCheckEndpoints (server/EchoOfDreams.ServerAPI/Api/Endpoints/ContentPreCheckEndpoints.cs:16-29)
— though that one is creator-facing/advisory and persists nothing; this needs the inverse (persist a
flag for admin visibility, say nothing alarming to the creator).
Correction — this is already confirmed, not an open question. moderation_check_results was
already generalized for standalone entity checks: 12b_generalize_check_results.sql made
publish_request_id nullable, added entity_type VARCHAR(30) + entity_id INTEGER, and added
CHECK (publish_request_id IS NOT NULL OR (entity_type IS NOT NULL AND entity_id IS NOT NULL)). So the
storage question is answered — no new table needed. What's actually still missing, now that the schema
question is off the table:
Prompt/sub_promptsneeds to become an entity the check-writer can address viaentity_type— today'sEntityRegistry.cs:198-200Promptentry is a route/display alias forEntityType.Mode, not a distinctentity_typevalue the standalone-check columns could reference cleanly.- An actionable admin queue — a flagged-content list, not just rows sitting in a table nobody looks
at. The check landing in
moderation_check_resultsdoesn't by itself create visibility; something has to surface "these presets got flagged" to an admin. - Dismiss/resolve state on a flagged report — today's schema generalization added where a standalone check result lives, not a resolution workflow for it.
- Re-checking on every edit while public, not just at the moment
is_publicflips true — otherwise a user publishes clean text, passes the check, then edits it to something else entirely and the report-style check never re-runs. The "check on publish" framing above needs to mean "check on every edit while live," not "check once." - One transactional gateway, not policy prose. "Re-check on every edit" only holds if there's a
single code path that publishing/editing public content is forced through — otherwise a different
endpoint or a direct SQL caller (the same class of gap as
the
fn_upsert_sub_promptownership hole above) can mutate a public preset's content without ever touching the check. The edit, the check run, the result write, and invalidating any prior admin resolution belong in one transaction, not three separately-callable steps a future endpoint could skip. - Dismissal needs to be tied to a content version/hash, not just a status flag. If an admin dismisses a flagged report and the preset is then edited, the dismissal must not silently cover the new text — a dismissal recorded against the content that was actually reviewed, invalidated the moment the content changes, so an edited-after-dismissal preset opens a fresh unresolved case rather than inheriting the old all-clear.
Creator-authored (Flavor) — a different, heavier problem, and currently an outright gap
Flavor content is not a candidate for the lightweight report-style model above. It's creator-written copy that ships to every reader of every Package resolving that creator's Model Profile — the same distribution shape as Mode content, which is why Mode content gets the full pre-approval pipeline. Treating Flavor like a personal Custom Instructions snippet would under-moderate creator-authored, audience-facing prose.
But today it's worse than under-moderated — it's unmoderated. Checked ModelProfile's existing
publish-check coverage (database/v1/functions/32_run_content_checks.sql:607-613): when a Package goes
through publish_requests, its linked (non-public) Model Profiles get swept in for check, but only
name/description — there is no join through any linked prompt/Flavor content the way the Mode
check block joins through prompt_mode_sub_prompt_links. So once Flavor overlays ship
(per Document Mode Editor),
their prompt text has no moderation coverage path at all unless one is deliberately added — this
predates and is independent of this doc's user-authored-preset work, but belongs on the same punch list
since it's the same substrate (sub_prompts) surfacing the same "is this content actually being
checked" question. The fix is likely mechanical — extend the Package/Model-Profile check sweep to join
through the Flavor's linking mechanism the same way the Mode check block already does for
prompt_mode_sub_prompt_links — but it's a distinct, separate change from the lightweight trigger above,
not a byproduct of it.
Summarization needs its own research pass
Correction — the premise in an earlier draft of this section was wrong, and worth recording so it
doesn't get re-asserted. It claimed summarization is prose end-to-end with no JSON parsing, based on
grepping only SummarizationStageBase (which has none). The actual JSON handling lives one layer down,
in SummarizationLlmService.cs, which the earlier research pass didn't check:
- Both default prompts already demand a fixed JSON shape —
{ "summary": "...", "keywords": ["...", ...] }(SummarizationLlmService.cs:25-47, bothDefaultSummarizeMessagesPromptandDefaultSummarizeSummariesPrompt). - Responses are already parsed as JSON, with real recovery logic: strip markdown code fences, then a
preamble-tolerant retry that pulls a JSON object out from behind a leaked
<think>block if the first parse fails, then fall back to raw text only if both attempts fail (ParseResponse/ParseJsonPayload,SummarizationLlmService.cs:377-429). - Object-valued
summaryfields get flattened to text; onlysummaryandkeywordssurvive into storage (content+keywords_jsononweb_summaries, perdatabase/v1/10_tables_memory.sql:66).
So this isn't "prose today, JSON tomorrow" — it's a fixed two-field JSON contract today (summary,
keywords, both hardcoded), and the dev's ask is extending that to a user-definable N-field contract
where a non-technical user names what else they want captured. Real new work, correctly rescoped: the gap
is the field-definition layer and the parser/validator that has to handle arbitrary user-chosen fields
(today's parser only ever looks for exactly summary and keywords), not "add JSON parsing that doesn't
exist."
The Trackers typed-value system (value_type:
freeform/numeric/percentage/enum/list/datetime, TrackerValueFormatter in
server/EchoOfDreams.Core/Services/Tracker/ turning a typed field definition into both the eval's
[type: …] prompt instruction and the parse/validate/render logic) is still the strongest reuse lead —
same "user names typed fields, backend builds the instruction and validates the output" shape, different
consumer.
Decided, not left open: a Summarization preset is one atomic aggregate, not three independently
selectable pieces. prompt_mode_contents already carries summarize_messages_prompt and
summarize_summaries_prompt as a pair — the per-window summarize prompt and the rollup-merge prompt that
combines summaries into a summary. A user-authored field schema has to be honored by both (a custom
field defined for message summarization has to survive the rollup, or it silently disappears the first
time two summaries merge). Modeling a Summarization preset as three independent, separately-selectable
sub_prompts rows (message prompt, rollup prompt, and some detached notion of "the schema") would let
someone pick an incompatible combination — the messages prompt asking for a mood field while the rollup
prompt has no idea mood exists. An earlier draft of this doc left this as an open question even though
its own reasoning already proves the answer — fixed: one versioned aggregate (both prompts + the
field schema, edited/selected/versioned as a single unit, whether or not it's stored as literal
sub_prompts rows underneath). A real design difference from Custom Instructions, which genuinely is
just one block of text and doesn't need this.
A sharper problem this creates: schema drift across a conversation's own summary chain. Note that Custom Instructions' live-FK answer makes this worse, not better, which is why Summarization is allowed to diverge: a live FK means a preset edit reaches the next rollup immediately. Even the weaker guarantee — "editing a preset doesn't retroactively rewrite past summaries" — isn't sufficient by itself. Summaries roll up — a later summarization call merges older summaries into a new one — and if a user edits their preset's field schema between two rollups, the rollup call runs the new schema's prompt against old summaries that were produced under the old schema. The old summary's custom fields may not exist under the new schema, or the new schema may expect fields the old summary never populated. This needs an explicit answer, not silence: either (a) a conversation's summary chain pins the preset version/schema that produced it and rollups only ever combine same-schema summaries (falling back to treating older summaries as unstructured prose input when schemas don't match), or (b) editing a Summarization preset that has any existing summaries forces a new preset id rather than an in-place edit, so "which schema produced this" is always unambiguous from the reference alone. Not decided — needs to be before Summarization's slice, not discovered when a rollup silently drops a field.
Context Budget accounting — presets must feed it correctly, not bypass it
Flagged separately because it's easy to lose: whatever a user selects (a Custom Instructions preset, a Summarization preset, an enabled Flavor) has to show up correctly in Context Budget, not just work at generation time. Traced what "correctly" means against the real mechanism rather than assuming a token-budget allocator exists:
- Context Budget is a display-only estimator today, not an enforcer. The public doc
(
docs/docs/features/context-budget.md:93-97) is upfront that it's a character-count approximation ("roughly 4 chars = 1 token"). That "display-only, read-after-the-fact" characterization is what's accurate to the code —GetContextBudgetAsync(ConversationBrowseRepository.cs:281-419) is a read-only reporting query run after the fact, estimating what today's independent, non-token-aware settings (message-count history cap, entry-count lorebook cap) would produce; nothing truncates or fits content to a token budget anywhere in the pipeline, and Custom Instructions itself is appended to the real prompt unconditionally (PromptContextManager.cs:282-314), with no budget check at all. The specificchars/4divisor quoted above is NOT accurate to the code — see the correction a few bullets down; don't read this bullet as endorsing it. So "calculated correctly" for v1 means the display line item is accurate, not that new enforcement gets built — worth confirming that scoping with the dev before assuming otherwise (see open question below). - Custom Instructions' budget line reads the raw
instructionscolumn by id (ConversationBrowseRepository.cs:385-393: aSELECT LENGTH(instructions) … WHERE id = @Idoffconv.CustomInstructionsId, then* 2 / 7). Under a live preset FK it needs a branch: preset FK set → size the preset's content; NULL → size the local row as today. That's a small change, not a design problem — the persona line twelve lines below it (:419-425,SELECT character_count * 2 / 7 FROM personas WHERE id = @Id) is already exactly this shape, chasing exactly this kind of FK. An earlier draft of this doc first called this "a concrete required edit," then over-corrected to "no change at all" under copy-on-apply; the accurate answer is a two-line branch modeled on the persona line directly beneath it. - Correction — the
chars*2/7divisor isn't an accident to reconcile, it's a documented, deliberate choice, and there's only a two-way gap, not three.04_tables_prompts.sql:166carries a migration comment: "Migratetoken_count_approxcolumns fromchars/4tochars*2/7(≈chars/3.5)" — the codebase already moved off/4because2/7"matches real BPE tokenization... better than/4" (same rationale repeated at10_entity_stats_materialized.sql:97-98). So the live endpoint's2/7andsub_prompts.token_count_approx's2/7already agree — the only real gap is that the public doc still sayschars/4(docs/docs/features/context-budget.md:93-97), stale relative to the divisor the backend already standardized on. Fix: update the public doc's stated formula to match the code, not "pick one of three floating divisors." - Correction — Summarization does NOT belong in Context Budget, and an earlier draft of this section
was wrong to propose it. Context Budget is specifically about what's sent in the chat request;
Summarization prompts run in a separate LLM call and the codebase already encodes exactly this
distinction on purpose:
10_entity_stats_materialized.sql:84-88(a related mode-stats view) explicitly excludessummarize_messages_prompt/summarize_summaries_promptfrom its chat-budget metric, with the comment "summarize_messages_prompt and summarize_summaries_prompt are excluded — they are only used during summarization, not chat requests, so they don't belong in a chat-budget metric." A Summarization preset's prompt text should never get its own Context Budget line for the same reason. What does already belong in Context Budget — and stays unaffected by this whole doc — is the resulting stored summary content once it's injected back into history. Correction: the budget line doesn't readweb_summaries.contentdirectly — it sums the storedcharacter_countcolumn (SUM(character_count) * 2 / 7,ConversationBrowseRepository.cs:547), which is downstream of whatever preset produced the summary. Prompt Presets doesn't need to add a Summarization line item; it needs to make surecharacter_countstays correctly maintained regardless of which preset generated the summary, which it already does — this is closer to "verify nothing broke" than "add new work" once the wrong claim above is retracted. - Flavor still needs its first budget line item — this part of the earlier draft holds. Flavor
content, unlike Summarization, is injected into the chat request (as a System row in the assembled
Base, per the Document Mode Editor design) — so it belongs in Context Budget the same way Custom
Instructions does, and currently has no budget hook at all (confirmed — no
Flavorreferences anywhere inPipeline/or the budget code, consistent with Flavors being unbuilt).
Decided (dev, 2026-07-25): display-only, like everything else. The Context Budget redesign and
warn/truncate enforcement are explicitly out of scope — nothing in the codebase enforces a token budget
for any section today, and presets don't become the first. "Calculated correctly" means exactly the
display fixes above: the preset-FK branch on the Custom Instructions line, Flavor's first line item
(when Flavor ships), and the public doc's stale chars/4.
Relationship to existing systems
sub_prompts/prompt_mode_sub_prompt_links— the storage/reuse substrate this whole feature sits on. Unaffected for existing Mode-linked rows.- Document Mode Editor — Model Profile Flavors (unbuilt) — a third consumer of the same substrate, but creator-authored, not user-authored (see the authorship split above) — its import-as-clone mechanic and moderation needs stay distinct from Custom Instructions/Summarization even though the storage row is shared. The "pick a saved prompt" UI can still be one shared component across all three (it's a picker, not a moderation policy), but the Flavor variant is scoped to a creator's own accessible prompts in the Profile editor, never mixed with a reader's personal preset library.
- Author's Notes — the steering sibling of Custom Instructions: plot direction for the next few messages, injected near the newest turns, visibly expiring. Deliberately not a preset consumer (no library, no default, no FK) — its existence is what lets Custom Instructions be cleanly "standing rules worth saving." Independent slice; nothing in this doc depends on it.
- Trackers —
TrackerValueFormatter's typed-field substrate is the strongest lead for the Summarization field-builder; see above. - Hybrid Narrative Pipeline §3 — planned to move summarization ownership to the beat mode; superseded for now (decided 2026-07-25, provisional): the Summarization preset applies to both pipeline types, and the beat mode supplies no summarization prompts. Hybrid summarization still reads the beat track — that part of the hybrid design is untouched; only prompt ownership moved. Revisit if beat-structured input degrades custom field extraction.
- Moderation Pipeline — the user-authored lightweight trigger
deliberately does not join that pipeline's
publish_requests/human-queue flow; Flavor content, by contrast, arguably should ride something closer to that pipeline given its audience-facing distribution — see Moderation model above. - Model Profiles — Hybrid-Ready — committed as in-scope for
this implementation (the dev asked twice), but specced in its own companion doc since its two pieces
(wiring the hybrid runtime to role-tagged
model_profile_entries; extending Flavor'starget_stagepastclassic_primary) are dependency-independent of presets. The companion doc owns the details; the connection back here is the sharedsub_promptssubstrate, the Flavor moderation-coverage gap named above, and slice 1's shared picker being reused for Flavor import.
Open questions
Decisions the dev already made in the conversation that produced this doc:
- Package-locked Custom Instructions are retired. Custom Instructions is purely user-controlled,
always — no exceptions. Decided; wording corrected 2026-07-31: what's retired is the lock
(
ConversationsEndpoints.cs:850-853, shipped in4fff5326d), not the package seed —fn_create_conversation_from_packagestill supplies an initial value the user owns from creation on, and that seed is already moderated at package publish (32_run_content_checks.sql:504-563, prompts area, verified). No locked-value path survives — that's the simplification. See What we are actually solving. Theinstructions_lockedcolumn/flag itself may still exist for the other package-lock purposes it serves — full column cleanup is out of scope here. - Reuse
sub_prompts/sub_prompt_contentsas the prompt-text storage substrate; don't invent a new way to store prompt text. Decided — the ownership/name/content/is_publicshape and the N:M-capable schema (not a proven live pattern — see the correction above) make this the durable choice over a bespoke text table. Correction: this does NOT mean zero new entities. Summarization needs a small new aggregate (summarization_presets) on top of this substrate — see What's new #2 — because its two prompts have to agree on one field schema, which a baresub_promptsrow can't express. The decision is "reuse the text storage," not "reusesub_promptsrows for absolutely everything." - Moderation is a lightweight, non-blocking, "report style" check on publish, for user-authored presets only — not the full Character/Lorebook pre-approval gate, and not the model Flavor content should use. Decided — see Moderation model.
- A Summarization preset is one atomic aggregate (messages prompt + rollup prompt + field
schema, edited/selected together), not three independently-pickable
sub_promptsrows. Decided on review — the doc's own reasoning about schema-compatibility between the two prompts already forced this answer; an earlier draft left it open when it shouldn't have. See Summarization needs its own research pass. (Earlier drafts said "versioned aggregate"; "atomic" is the part that was load-bearing — whether it needs a version counter depends on the attach question slice 3 settles.) - A conversation references its preset by a live FK, and edits propagate. The invariant that makes
that safe is "you only ever reference a row you own" — importing someone else's public preset clones it
into your library first. Editing instructions inside a conversation detaches it to local text. No
version counter, no history; the
purposediscriminator andis_deletedare the onlysub_promptsschema additions. Decided 2026-07-25. Mirrorsweb_conversations.user_persona_id, the working precedent for the same shape. Verified additive: there is noDELETE FROM sub_promptsanywhere in the schema, andprompt_modesnext door already soft-deletes. Cost: the 5,000-char cap and injection check gain a second site at preset save/edit (re-running on every edit) while staying on conversation-save for local text — which is work slice 2's moderation gateway needs regardless. Supersedes a copy-on-apply decision recorded earlier the same day; that draft traded away propagation to solve a problem that only existed for other people's presets, which import-clones-first handles directly. See Mutation semantics. - A user can set one Custom Instructions preset as their default for new conversations, mirroring
the existing default-persona mechanism. Decided 2026-07-25. Custom Instructions only — Summarization
and Flavor get no default in this slice. Not a new pattern:
user_settingskey + ownership-enforcing-JOIN resolver + server-side application in both conversation-create paths, all cloned fromPersona.DefaultId. Precedence on the package path: the package's owncustom_instructionswins when it supplies one, the user default fills in when it doesn't. Branching must not re-apply the default, matching the persona carve-out. See A user-level default preset. - The shared "pick a saved prompt" UI ships in slice 1, not deferred to a later "unify" slice — per the repo's rule-of-two convention, with two consumers already named up front. Decided on review — see What's new #5.
- Model Profiles becoming hybrid-ready is in scope for this implementation, not an adjacent piece of work this doc merely mentions — and it now lives in its own companion spec: Model Profiles — Hybrid-Ready. Decided 2026-07-25 (the dev asked for the split): scope stays committed, only the paper moved — its two pieces are dependency-independent of presets, so the companion doc lets the role-tagged Beat/Prose wiring be picked up without reading this design first. Slice 4 below is now a pointer.
- Context Budget stays display-only — the redesign and warn/truncate enforcement are out of
scope. Decided 2026-07-25. "Calculated correctly" means the display line items are accurate
(the preset-FK branch, the Flavor line, the stale
chars/4doc fix), like every other section today. No new enforcement infrastructure. - A Summarization preset applies to both pipeline types — classic and hybrid — for now. Decided 2026-07-25, explicitly provisional ("we will see if we need changes"). This supersedes, for now, Hybrid Pipeline §3's plan for the beat mode to own the summarization prompts: once presets decouple summarization from Mode, the user's preset (or the built-in default) supplies the prompts in both pipelines, and the beat mode supplies none. The hybrid nuance to watch: hybrid summarization reads the beat track, so a preset's prompts run against beat-structured input there rather than prose — if that degrades custom field extraction in practice, this is the decision to revisit.
Still open, mine to research/decide before a slice starts:
- Exact shape of the
purposediscriminator onsub_prompts— justcustom_instructionsnow (see What's new #1 correction: Summarization no longer uses this discriminator at all, it gets its ownsummarization_presetsaggregate instead). -
summarization_presetsaggregate's exact shape — field-schema storage (JSON column vs. a child table mirroring Trackers' typed-field-definition table), and whether it needs its ownis_deleted. - The
fn_upsert_sub_promptownership gap — add an explicit ownership check (function-level or endpoint-level) before any standalone-preset edit path can call it directly. See the authorization gap. The single hardest-edged slice-1 blocker, and independent of the mutation decision — it's about editing a preset row you don't own, not about how content reaches a conversation. A real hole, not a design preference. - The attach-time read-authz contract (purpose match, caller-owns-the-row, no-enumeration-by-guessing) — small and ordinary; see the list at the end of the authorization gap. Still slice 1, but no longer an open design question.
- Adding the 5,000-char cap and the injection check at preset save/edit (they also stay on conversation-save for the local-text path — two sites, not a move) — required by the live FK, since the preset's text never passes through the conversation-save path that runs them today. Slice 1, and it should land on the same transactional gateway slice 2's re-check-on-edit needs rather than as a separate one-off. See the authorization gap.
- Does Summarization attach live like Custom Instructions, or pin its schema at attach time? It has a constraint Custom Instructions doesn't — schema drift across rollups wants the field schema stable for a conversation's whole life, which a live FK doesn't give. The two consumers are allowed to differ here. See the Summarization lean. Blocks Summarization's slice, not slice 1.
- Stored-result design for user-defined summary fields (raised on external review, correct):
the aggregate design says what the prompts look like, but not where the extracted values live.
web_summariestoday stores exactlycontent+keywords_json(10_tables_memory.sql:66) — an N-field schema needs (a) structured storage for arbitrary user-named fields, (b) per-summary provenance: which preset id and which schema version/hash produced this row, and (c) the exact mixed-schema rollup behavior when same-schema-only merging isn't possible (the fall-back-to-prose path in the schema-drift problem, made concrete). All three before slice 3's UI, not after. - Building the admin-facing side of the now-confirmed
moderation_check_resultsstandalone-entity support: the transactional edit/check/dismiss gateway, dismissal tied to content version, and re-check-on-every-edit behavior — see the numbered list in Moderation model. - Exact placement of the Summarization preset picker in the chat UI. The dev's lean: a new
"Options" modal in chat, near the Context Budget display. The real estate today is the How drawer's
section stack (
HowDrawer.tsx:52-81: Behavior → Context Budget → Model → Mode → Memory → Active Features) — the Memory section is the natural neighbor, since it already owns the summary-browsing UX the preset would be steering. Whether that means a new modal or a new drawer section is slice-3 UI design; recorded as a lean, not a commitment.
Suggested slicing (leans, not committed)
- Substrate: one thing to settle first — the
fn_upsert_sub_promptownership gap, which is a real hole rather than a design choice and must be closed before any standalone edit path can call that function. (Mutation semantics and legacy migration used to gate this slice too; both are now decided/dissolved.) Then build:is_deletedonsub_prompts, thepurpose='custom_instructions'discriminator, a preset library (private-only, no sharing yet), the nullablecustom_instructions_preset_idFK on the conversation, attach / detach-on-local-edit behavior, and the attach-time read-authz check. Resolve the FK everywhere the text is read — the core runtime change: the prompt build (PromptContextManager.AppendCustomInstructionsAsync,PromptContextManager.cs:278-311, which today only knows the local row) and the conversation read API that surfaces the text in the chat drawer, both branching FK-set → preset content, NULL → local row. Add the 5,000-char cap and the injection check at preset save/edit (required by the live FK — the preset's text never passes through the conversation-save path that runs them today; they stay on conversation-save for local text — two sites, not a move), and keep ownership-before-compute exactly where it is. Plus the shared "pick a saved prompt" UI (built here per rule-of-two, not deferred — see What's new #5), showing linked-vs-detached state so a user can tell why a preset edit did or didn't reach a given chat. Also in this slice: the user-level default preset — theCustomInstructions.DefaultPresetIdsetting, its resolver, and its application in both conversation-create paths: plainCOALESCE(explicit, default)on the new FK column infn_create_conversation, but guarded infn_create_conversation_from_package— the default applies only when the package supplies nocustom_instructionstext, else a bare COALESCE would create the forbidden both-set state (package local text + default FK). Plus the three/defaultroutes, the "set as default" affordance, and the two registration points (89_enforce_setting_write_scopes.sql,SettingsSeedingTests.cs). A column-for-column clone of the default-persona mechanism, so it rides along here rather than earning its own slice — see A user-level default preset. Smallest possible slice that proves the standalone (non-mode-linked) path works end to end for Custom Instructions specifically — Summarization'ssummarization_presetsaggregate is deliberately slice 3's problem, not this one's, since it's a different shape. Already done, ahead of the slice: retiring the package-lock enforcement on Custom Instructions (shipped 2026-07-22, commit4fff5326d—ConversationsEndpoints.cs,PackageLockDto,PackageRepository,WhoDrawer.tsx, changelog trigger, Echo Guide KB; verified live against a package withinstructions_locked = TRUEstill set). Small but don't forget: branch the Context Budget custom-instructions line on the preset FK (ConversationBrowseRepository.cs:385-393, modeled on the persona line at:419-425), carry the FK across infn_branch_conversation, and fix the public Context Budget doc's stalechars/4claim to match the code'schars*2/7(see Context Budget accounting). - Sharing + moderation: flip
is_publiclive, build the import-as-clone action (the actual sharing mechanic under rule 3 — browsing another user's public preset clones it into your library; no cross-user FK ever exists), wire the inline keyword check, givePrompta realentity_typethe standalone-check columns can address, and build the admin flagged-content queue as one transactional gateway with dismiss/resolve state tied to a content version and re-check-on-edit (moderation_check_resultsalready supports the storage side — see Moderation model). - Summarization decoupling: its own research pass first (see
Summarization needs its own research pass) — build the
summarization_presetsaggregate (owning twosub_prompt_contentsrows + a field schema, per What's new #2), resolve the schema-drift-across-rollups provenance question and the stored-result design (structured storage for user-named fields + per-summary preset/schema provenance onweb_summaries— see the open item above; the schema/result design lands before the UI), extend the fixedsummary/keywordsJSON contract to user-definable fields, and reuse the Tracker typed-field substrate where it fits. Reuses slice 1's shared picker (pointed at the aggregate, not asub_promptsrow), surfaced in the chat UI per the placement lean above (an "Options" surface near Context Budget / Memory in the How-drawer stack). Applies to both pipeline types per the decided item above — the beat mode supplies no summarization prompts. Does not touch Context Budget — Summarization prompts are correctly excluded from it (see the correction above); only the existing "summaries" line'scharacter_countbookkeeping needs to keep working unchanged. - Model Profiles hybrid-ready — committed scope, specced in the companion doc: Model Profiles — Hybrid-Ready, including its own slicing and the dependency ordering between its two pieces. What stays anchored here: the Flavor content-moderation gap from Moderation model, slice 1's shared picker being reused for Flavor import, and Flavor's first Context Budget line item — all three ride with the companion doc's Flavor half, since they need Flavor to exist.
This ordering isn't a commitment — slice 0 for whichever piece gets picked up first should answer most of the open questions above as a side effect, the same way any slice 0 does.
Slice 1 — as built (2026-08-04)
Slice 1 is implemented. This section records what shipped and, more importantly, where the build diverged from what this doc predicted — divergences only, so a later reader can tell design intent from implementation fact without re-deriving either.
Divergences from the plan above
The
fn_upsert_sub_promptownership check is scoped by row kind, NOT a blanketcreated_by_user_id = p_user_id. This doc proposed the blanket form. Building it that way would have been a regression: the mode-prompt PUT passes the caller's id, not the row owner's (CreatorModeEndpoints, gated byRequireEntityAccess(… a => a.can_edit …)), so a collaborator legitimately editing a shared mode's sub-prompt would have started failing. Mode sub-prompts are authorized by their parent Mode; only standalone presets are authorized by ownership. So the guard fires only forpurpose IS NOT NULLrows — which is where the actual hole was, since those are the rows with no parent to gate them. A regression test pins the collaborator case so a future "tighten this" change can't silently break shared-mode editing.The FK is resolved once in
conversation_view, not branched separately in two readers. This doc saidPromptContextManager.AppendCustomInstructionsAsyncand the conversation read API would each branch. Both already read throughconversation_view(WebConversationRepository.GetCustomInstructionsForConversationAsyncis the prompt hot path), so the branch became oneCOALESCE(preset content, local text)in the view.PromptContextManageris unchanged. One place means the prompt build and the API cannot drift into disagreeing about what a conversation's instructions are."Both set" is unrepresentable at the table, not just avoided by writers. Added
check_web_conversations_instructions_not_both. The doc treated this as a rule the attach path and the local-edit path each had to uphold; making it a CHECK means a future third writer cannot violate it. Same move for the substrate boundaries:purpose's vocabulary andpreset ⇒ provider_key IS NULLare table CHECKs in addition to writer assertions.custom_instructions_preset_idcarries no FK constraint, mirroringuser_persona_id(which has none) rather than thecustom_instructions_idcolumn next to it (which does). Soft delete keeps the referent alive, so there is nothing forON DELETEto do.fn_create_conversationgained a 13th parameter (p_custom_instructions_preset_id) soCOALESCE(explicit, default)is real rather than default-only. It is not exposed on the REST create endpoint in slice 1 — attach-after-create is the UI flow — but the SQL contract supports it and is tested.fn_update_conversation_authorized'sRETURNS TABLEhad to be extended. It is a hand-maintained subset ofconversation_view, so new view columns do not arrive for free; without the four preset columns (custom_instructions_preset_id,_uuid,_name,_is_deleted) every conversation PUT would have responded as though the conversation had just detached.Attach refuses a foreign conversation with 403, while every preset refusal is a uniform 404. The preset side is the enumeration-sensitive one and collapses all four failure modes (not yours / missing / wrong purpose / deleted) into one response. The conversation side matches its sibling
UpdateCustomInstructionsexactly rather than inventing a second convention; changing that pattern is a separate decision that should move both endpoints together.EntityRegistry'sPromptentry was deliberately left alone (DeletedColumn: null). Setting it tois_deletedwould stop uuid→id resolution for soft-deleted presets, which would break the already-linked conversations that must keep resolving them. Liveness is filtered explicitly in the preset queries instead.
Also in this change, unrelated to presets
- Fixed a pre-existing broken solution build at
HEAD:WebTrackerEvalServiceTests.FakeTrackerRepositorydid not implementITrackerRepository.GetPageByOwnerAsync/CountByOwnerAsync. Two throw-on-unused stubs, matching the fake's existing shape. - Corrected the public Context Budget doc's stale
chars/4to ~3.5 characters per token, matching thechars*2/7the backend standardized on (docs/docs/features/context-budget.md).
Not done in slice 1 (deliberately)
Sharing / is_public / import-as-clone, the admin flagged-content queue, and dismissal-tied-to-content-version
are all slice 2 and are untouched. The write gateway
(CustomInstructionsPresetGateway) is structured as the single path they will join.
Acceptance Criteria — Slice 1 only (private Custom Instructions presets)
The feature is not done until every box below is verified against the running product.
User use cases — satisfiable + accessible (verify by driving the UI, not the code)
- UC-1 — Save a preset. As a user, I can create a named Custom Instructions preset and see it in my library — reachable from a discoverable entry point in the Dream Vault without insider knowledge (no URL typing, no dev tools).
- UC-2 — Edit a preset. As a user, I can rename a preset and change its text from the library, and the change is visible on reload.
- UC-3 — Remove a preset. As a user, I can remove a preset from my library; it disappears from the library list and from every preset picker.
- UC-4 — Attach a preset to a conversation. As a user, in an open chat I can pick one of my saved presets as that conversation's Custom Instructions, from the same surface that already owns the Custom Instructions field (the Who drawer) — no separate hidden screen.
- UC-5 — See why a preset edit did or didn't reach a chat. As a user, the Custom Instructions surface tells me whether this conversation is linked to a named preset or holds locally edited text, in words, without me having to compare the text by eye.
- UC-6 — Detach by editing. As a user, editing the instructions text inside a conversation keeps my edit for that conversation only, and the UI shows it is no longer linked to the preset.
- UC-7 — Set a default. As a user, I can mark one preset as my default for new conversations from the library, the default is visibly pinned at the top of the list, and I can unset it.
- UC-8 — Default lands. As a user with a default preset set, a conversation I start fresh from a character opens already linked to that preset, with no extra step.
Behavior
- B-1 — Live FK propagation. Editing a preset's text changes the instructions used by every conversation still linked to it, with no per-conversation action. Observable in Context Budget and in the built prompt.
- B-2 — Prompt build resolves the FK. With a preset attached, the assembled system prompt
contains the preset's text in the Custom Instructions position
(
PromptContextManager.AppendCustomInstructionsAsync). With no preset attached, it contains the local row's text exactly as before. - B-3 — Conversation read API resolves the FK. The conversation read surface returns the preset's text as the effective custom instructions when the FK is set, plus enough state (preset id + name) for the client to render "linked to X".
- B-4 — Attach clears local text. Attaching a preset to a conversation that already had typed text clears the local row. The both-set state is never representable — verified by reading the row after an attach.
- B-5 — Local edit detaches.
PUT /api/conversations/{id}/custom-instructionswith text clearscustom_instructions_preset_idand writes the local row, in one operation. - B-6 — Soft delete keeps linked conversations working. Removing a preset from the library leaves conversations already linked to it resolving its text unchanged — the chat does not lose its instructions.
- B-7 — Soft delete blocks all forward selection. A removed preset is absent from the library list, is rejected by the attach endpoint, and is ignored by the default resolver — so it can never reach a new conversation.
- B-8 — Default auto-applies on create.
fn_create_conversationwith no explicit preset resolvesCustomInstructions.DefaultPresetIdand sets the FK. An explicitly-passed preset wins over the default. - B-9 — Ownership check in
fn_upsert_sub_prompt. The function itself refuses to update asub_promptsrow whosecreated_by_user_idis not the caller — verified by calling the function directly, not only through an endpoint. - B-10 — 5,000-char cap and injection check run at preset save AND edit. Both fire on create and on every update of preset text, through one shared gateway path, not per-endpoint copies.
- B-11 — Context Budget reports the linked preset. The Custom Instructions line in Context Budget reflects the preset's size when the FK is set, and the local row's size when it is not.
- B-12 — Default routes. The three
/defaultroutes (GET/PUT/DELETE) read, set, and clear the default, mirroringPersonasEndpoints.
Invariants that must stay true (carve-outs — the spec'd-free/baseline paths)
- I-1 — Ad-hoc typed text stays first-class, forever. A conversation with no preset behaves exactly as it does today: type, save, resolve, budget-count. No migration, no backfill, no preset required. Verified on a conversation created before this slice.
- I-2 — Ownership-before-compute stays where it is. The conversation custom-instructions endpoint still verifies conversation ownership before the embedding/injection check runs — a non-owner never triggers an embedding charge.
- I-3 — The 5,000-char cap and injection check stay on conversation-save. They gained a second site at preset write; they did not move. The local-text path still runs both.
- I-4 — Package text wins over the user default.
fn_create_conversation_from_packageapplies the default preset only when the package supplies nocustom_instructionstext. When the package supplies text, the conversation starts detached with that text and a NULL preset FK. - I-5 — Branch does not re-apply the default.
fn_branch_conversationcopies the parent's preset FK including NULL — a user who detached must not get the default re-applied on branch. - I-6 — Existing mode sub-prompts are untouched. Mode assembly, mode copy/clone, mode content
checks, and entity stats behave identically for
purpose IS NULLrows. Preset rows never appear in a mode. - I-7 — No package lock returns. Custom Instructions remains always user-editable regardless of package origin (retired 2026-07-22); nothing in this slice reintroduces a lock.
- I-8 — Presets are private in slice 1. No endpoint in this slice flips
is_public, and no surface lists another user's presets.
Edges
- E-1 — Cross-user edit refused. User A calling the preset update endpoint with user B's preset id fails, and the failure is indistinguishable from "no such preset" — no existence leak.
- E-2 — Cross-user attach refused. User A attaching user B's preset id to their own
conversation fails with the same uniform not-found shape (mirrors
ConversationsEndpoints.cs:908-913). - E-3 — Enumeration gives nothing. Probing sequential/guessed preset ids yields the same response for "exists but not mine" and "does not exist", on both attach and update.
- E-4 — Wrong-purpose id refused. Attaching a
purpose IS NULLmode-sectionsub_promptsrow (even one the caller owns) is rejected by the attach path. - E-5 — Preset row rejected by the mode-link writer. A
purpose='custom_instructions'row cannot be linked into a Mode viaprompt_mode_sub_prompt_links. - E-6 — Shape asserted at the writer. Preset rows are written with
provider_key IS NULL; the writer rejects a non-NULLprovider_keyrather than trusting the UI. - E-7 — Over-length preset rejected. Preset text at 5,001 characters is refused with a clear message on both create and update.
- E-8 — Injection text rejected at preset write. Preset text matching the injection-pattern check is refused, with the same user-facing framing the conversation path already uses.
- E-9 — Empty library. A user with no presets sees a purposeful empty state in the library and in the picker — not a blank panel or a spinner that never resolves.
- E-10 — Stale default resolves to nothing. A default pointing at a removed, non-owned, or non-existent preset resolves to NULL — new conversations simply get no preset, no error.
- E-11 — Detach to nothing. Clearing the instructions text on a preset-linked conversation leaves it with neither a preset nor local text, and the prompt omits the section entirely.
- E-12 — Unauthenticated. Every new endpoint refuses an anonymous caller.