A personality belongs to a person

Owner's correction to 1.4.0: a model's character is per (model, person), and only
the description and the notes stay instance-wide. Two people talking to one model
are not talking to the same personality, and neither can see the other's.

The administrator's box becomes the DEFAULT, resolved by `personas.effective` as
a fallback and never as a layer -- two personalities at once contradict each
other with nothing to say which is losing, which is the reasoning behind "system
prompts replace, never stack". `persona_write` takes no argument naming a model
or a person; both come from the ToolContext, so it can only write the character
it has with whoever it is talking to, and it never touches the default.

Impressions move to their own table. Not a `kind` column: 1.4.0 shipped
`UNIQUE(model_key, owner_id)`, SQLite cannot alter a constraint and this schema
is additive-only, so a discriminator would leave an upgraded instance unable to
hold both rows for one pair. That leaves the first MANUAL_STEPS entry this
project has had -- the two shapes are indistinguishable, so nothing rewrites
them: a repair would be guessing at text that is read back in the first person.

TWO BUGS FROM A PHONE

`min-width` beats both `width` and `max-width` -- CSS clamps width to max-width
and then raises the result to min-width -- so `.canvas` and `.terminal` were
384px wide on every screen narrower than that, their `min(…, 100vw)` cap
overruled, and `.inspector` had no cap at all on a width that is a preference
draggable to 2400px. None of it scrolled sideways, because all three are
`position: fixed` and fixed overflow does not extend the scrollable area -- which
is exactly why the 1.1.0 narrow pass reported these pages clean. `min-width: 0`
in the overlay query, full width below the phone breakpoint, tablet column kept.

And the install button now says why it is absent. Measured against the live
instance: the manifest meets every Chrome criterion and the blocker is a
certificate from a private CA, so the origin is not trustworthy, the service
worker is refused and no install is offered. `base.html` had been swallowing that
with an empty catch -- which kept the page working, the reason it was there, and
threw away the only evidence. It now records the outcome and `app.js` turns it
into a sentence naming the certificate, which is the cause the old hint did not
mention.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-26 12:20:40 +00:00
co-authored by Claude Opus 5
parent df52ec9d96
commit ac51dd46cc
20 changed files with 1019 additions and 201 deletions
+122 -26
View File
@@ -1,8 +1,9 @@
"""A model's personality, and its read of the person it is talking to.
"""A model's personality with one person, and what it makes of them.
Both live in one table (`db/models/persona.py` says why) and both reach the
model the way the memories block does: a `{{variable}}` and a fragment, never a
second system-prompt layer.
Both are per (model, person) -- see `db/models/persona.py` for the shape and for
why they are two tables. The administrator's default persona (`owner_id IS NULL`)
is a **starting point**, resolved by `effective` and never stacked on top of
somebody's own.
Three rules, and each is here rather than in the column so a write that breaks
one can be trimmed with an explanation instead of failing somebody's turn -- the
@@ -11,13 +12,13 @@ rule `memories.py` already follows:
* **Capped.** Both texts are in front of the model on every single request, so
a personality that grows without limit is a context window that shrinks
without anybody noticing.
* **Snapshotted before every change.** A model may rewrite its own persona, so
what stops a bad rewrite being permanent is a record and a way back. Not a
gate: the roadmap already states the same limit for model-written skills.
* **A reflection belongs to the person it is about.** It is keyed on their id,
read only for them, and shown to them in their own settings. A model-written
note about somebody that they cannot see is not something this application
should hold.
* **A personality is snapshotted before every change.** A model may rewrite its
own, so what stops a bad rewrite being permanent is a record and a way back.
Not a gate: the roadmap states the same limit for model-written skills. An
impression is not snapshotted, for the reason its own docstring gives.
* **Both belong to the person they concern.** Keyed on their id, read only for
them, and shown to them in their own settings. A model-written note about
somebody that they cannot see is not something this application should hold.
"""
from __future__ import annotations
@@ -27,7 +28,14 @@ import logging
from sqlalchemy import select
from sqlalchemy.orm import Session as DBSession
from lembas.db.models import AUTHOR_MODEL, AUTHOR_USER, Persona, PersonaRevision, User
from lembas.db.models import (
AUTHOR_MODEL,
AUTHOR_USER,
Impression,
Persona,
PersonaRevision,
User,
)
log = logging.getLogger(__name__)
@@ -47,16 +55,14 @@ MAX_VIEW_CHARS = 800
MAX_REVISIONS = 20
def _limit(reflection: bool) -> int:
return MAX_VIEW_CHARS if reflection else MAX_PERSONA_CHARS
def get(db: DBSession, model_key: str, owner: User | None) -> Persona | None:
"""The persona for a model, or that model's read of one person.
"""One personality row, exactly as asked for and with no fallback.
`owner=None` asks for the model's own persona. There is no fallback between
the two: a reflection is not a kind of persona and must not stand in for a
missing one.
`owner=None` asks for the administrator's default. Use `effective` to ask the
question the prompt asks -- "who is this model with this person" -- which is
where the fallback belongs.
"""
if not model_key:
return None
@@ -68,8 +74,23 @@ def get(db: DBSession, model_key: str, owner: User | None) -> Persona | None:
).first()
def reflections_for(db: DBSession, owner: User | None) -> list[Persona]:
"""Every model's read of one person, for that person's own settings page."""
def effective(db: DBSession, model_key: str, owner: User | None) -> Persona | None:
"""This person's personality for this model, or the default if they have none.
The fallback is what makes an administrator's default mean anything: until
the model has written something of its own with somebody, that is who it is.
Once it has, the default stops applying to them -- it is a starting point and
not a layer, because two personalities stacked would contradict each other and
nobody could tell which was losing.
"""
own = get(db, model_key, owner)
if own is not None:
return own
return get(db, model_key, None) if owner is not None else None
def personas_of(db: DBSession, owner: User | None) -> list[Persona]:
"""Every personality this person has, for their own settings page."""
if owner is None:
return []
return list(
@@ -81,6 +102,68 @@ def reflections_for(db: DBSession, owner: User | None) -> list[Persona]:
)
def impression(db: DBSession, model_key: str, owner: User | None) -> Impression | None:
if not model_key or owner is None:
return None
return db.scalars(
select(Impression).where(
Impression.model_key == model_key, Impression.owner_id == owner.id
)
).first()
def impressions_for(db: DBSession, owner: User | None) -> list[Impression]:
"""Every model's read of one person, for that person's own settings page."""
if owner is None:
return []
return list(
db.scalars(
select(Impression)
.where(Impression.owner_id == owner.id)
.order_by(Impression.model_key)
)
)
def write_impression(
db: DBSession,
*,
model_key: str,
owner: User,
content: str,
author: str = AUTHOR_MODEL,
) -> Impression:
"""Set what a model makes of somebody. Replaces; no history kept.
Deliberately without the snapshotting `write` does. An impression is meant to
change as the model learns, so a history of it would be a log of somebody
being reassessed -- and the control that matters is that they can read it and
delete it, which they can.
"""
if not model_key:
raise ValueError("There is no model to write an impression for.")
text = (content or "").strip()[:MAX_VIEW_CHARS]
row = impression(db, model_key, owner)
if row is None:
row = Impression(
model_key=model_key,
owner_id=owner.id,
content=text,
author=author if author in (AUTHOR_USER, AUTHOR_MODEL) else AUTHOR_MODEL,
)
db.add(row)
else:
row.content = text
row.author = author if author in (AUTHOR_USER, AUTHOR_MODEL) else AUTHOR_MODEL
db.commit()
return row
def clear_impression(db: DBSession, row: Impression) -> None:
db.delete(row)
db.commit()
def personas_for(db: DBSession, model_keys: list[str]) -> dict[str, Persona]:
"""Every model's own persona, keyed by model id. For the admin screens."""
if not model_keys:
@@ -111,14 +194,13 @@ def write(
if not model_key:
raise ValueError("There is no model to write a personality for.")
reflection = owner is not None
text = (content or "").strip()[: _limit(reflection)]
text = (content or "").strip()[:MAX_PERSONA_CHARS]
row = get(db, model_key, owner)
if row is None:
row = Persona(
model_key=model_key,
owner_id=owner.id if reflection else None,
owner_id=owner.id if owner is not None else None,
content=text,
author=author if author in (AUTHOR_USER, AUTHOR_MODEL) else AUTHOR_MODEL,
)
@@ -199,13 +281,21 @@ def clear(db: DBSession, row: Persona) -> None:
def block(db: DBSession, model_key: str, owner: User | None) -> str:
"""The text as the prompt carries it, or "" when there is nothing to say.
"""The personality as the prompt carries it, or "" when there is none.
Empty and disabled are the same answer on purpose: the fragments that read
this are gated on it with `requires`, so both make the whole section vanish
rather than leaving a heading above nothing.
"""
row = get(db, model_key, owner)
row = effective(db, model_key, owner)
if row is None or not row.enabled:
return ""
return (row.content or "").strip()
def view_block(db: DBSession, model_key: str, owner: User | None) -> str:
"""What the model makes of this person, as the prompt carries it."""
row = impression(db, model_key, owner)
if row is None or not row.enabled:
return ""
return (row.content or "").strip()
@@ -217,9 +307,15 @@ __all__ = [
"MAX_VIEW_CHARS",
"block",
"clear",
"clear_impression",
"effective",
"get",
"impression",
"impressions_for",
"personas_for",
"reflections_for",
"personas_of",
"view_block",
"revert",
"write",
"write_impression",
]