persona

package
v0.1.0-alpha.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2026 License: GPL-3.0 Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package persona owns named personalization presets. A persona is a portrait, a display name, and values across the personalization axes the prompt already composes — reply register, reaction style, behavior profile, starting zone.

It is deliberately not a second personalization system and not a prompt fragment: every field here maps to a value ComposeSystem already consumes, so a persona can change how the assistant sounds and can never change the motion contract, the capability gates, the speed limits, or the user's own anatomy vocabulary. See docs/persona-page.md §3 for the full guardrail table.

Index

Constants

View Source
const (
	// LoreModeOff keeps saved lore out of model prompts.
	LoreModeOff = "off"
	// LoreModeRelevant selects enabled entries whose keywords match recent chat.
	LoreModeRelevant = "relevant"
	// LoreModeFull selects every enabled entry within the hard storage budget.
	LoreModeFull = "full"

	// MaxLoreEntries bounds the number of saved entries per persona.
	MaxLoreEntries = 8
	// MaxLoreTextChars bounds one entry before it reaches prompt composition.
	MaxLoreTextChars = 500
	// MaxLoreTotalChars bounds all saved lore for one persona.
	MaxLoreTotalChars = 2000
	// MaxLoreKeywords bounds the relevant-mode match vocabulary per entry.
	MaxLoreKeywords = 12
	// MaxLoreKeywordChars bounds one relevant-mode keyword or phrase.
	MaxLoreKeywordChars = 40
)
View Source
const (
	// ArchiveMediaType is the content type used for portable persona archives.
	ArchiveMediaType = "application/vnd.magichandy.persona+zip"
	// ArchiveExtension keeps persona archives distinct from generic ZIP files.
	ArchiveExtension = ".mhpersona"
	// MaxArchiveBytes bounds the compressed upload before the ZIP reader sees it.
	MaxArchiveBytes = 4 << 20
)
View Source
const (
	// MaxPortraitBytes bounds an accepted portrait. The browser is asked for a
	// downscaled JPEG, so anything near this is a client that ignored the
	// contract rather than an unusually detailed picture.
	MaxPortraitBytes = 2 << 20
	// MaxPortraitEdge is the largest dimension accepted. Resizing happens in the
	// browser, on the same canvas path video covers already use: server-side
	// scaling would need a new image-scaling dependency or FFmpeg, and FFmpeg is
	// deliberately optional. A portrait must not be what makes it mandatory.
	//
	// The server still checks the dimensions rather than trusting the client,
	// because this endpoint writes a file to disk.
	MaxPortraitEdge = 1024
)
View Source
const (
	// MaxNameChars keeps a name legible in a tile. Longer names truncate with an
	// ellipsis rather than wrapping a portrait card to three lines.
	MaxNameChars = 60
	// MaxDescriptionChars reuses the bound the persona description has always
	// had, because it enters the prompt through the same validated path.
	MaxDescriptionChars = config.MaxLLMPersonaDescriptionChars
	// MaxPromptSetIDChars bounds the stored behavior-profile reference. Membership
	// is not checked here: a user prompt set can be deleted after a persona
	// selects it, and resolution already falls back to the bundled default rather
	// than failing a turn.
	MaxPromptSetIDChars = 80
)

Variables

View Source
var (
	// ErrPortraitInvalid reports a payload that is not a usable JPEG.
	ErrPortraitInvalid = errors.New("portrait is not a supported JPEG")
	// ErrPortraitNotFound reports a persona with no stored portrait.
	ErrPortraitNotFound = errors.New("portrait has not been set")
)
View Source
var (
	// ErrNotFound reports an unknown persona identifier.
	ErrNotFound = errors.New("persona not found")
	// ErrInvalid reports a persona that cannot be stored as described.
	ErrInvalid = errors.New("invalid persona")
	// ErrLimit reports that the persona library is full.
	ErrLimit = errors.New("persona limit reached")
)

Errors distinguish absence, rejection, and capacity so the API can map them to 404, 400, and 409 without inspecting strings.

Functions

func LoreModes

func LoreModes() []string

LoreModes returns the server's accepted vocabulary for the editor.

func ValidID

func ValidID(id string) bool

ValidID reports whether an identifier is one this package minted. Portrait paths are built from it, so this is a security boundary and not a nicety.

func ValidLoreMode

func ValidLoreMode(mode string) bool

ValidLoreMode reports whether a persona's prompt policy is code-owned.

Types

type Draft

type Draft struct {
	Name             *string `json:"name,omitempty"`
	Description      *string `json:"description,omitempty"`
	ChatVoice        *string `json:"chat_voice,omitempty"`
	ReactionStyle    *string `json:"reaction_style,omitempty"`
	PromptSetID      *string `json:"prompt_set_id,omitempty"`
	DefaultFocusArea *string `json:"default_focus_area,omitempty"`
	LoreMode         *string `json:"lore_mode,omitempty"`
}

Draft is the writable surface. Pointer fields mean "omitted preserves the saved value", matching the settings update contract, so a PATCH that carries only a name cannot silently reset a register.

type LoreDraft

type LoreDraft struct {
	Text     *string   `json:"text,omitempty"`
	Keywords *[]string `json:"keywords,omitempty"`
	Enabled  *bool     `json:"enabled,omitempty"`
}

LoreDraft is the partial mutation surface for a lore entry.

type LoreEntry

type LoreEntry struct {
	ID        string   `json:"id"`
	PersonaID string   `json:"persona_id"`
	Text      string   `json:"text"`
	Keywords  []string `json:"keywords"`
	Enabled   bool     `json:"enabled"`
	CreatedAt string   `json:"created_at"`
	UpdatedAt string   `json:"updated_at"`
}

LoreEntry is one bounded fact about a persona. Keywords are matching data, not prompt instructions; only Text is quoted into the composed prompt.

type LoreSelection

type LoreSelection struct {
	Texts      []string `json:"-"`
	EntryIDs   []string `json:"entry_ids"`
	Characters int      `json:"characters"`
}

LoreSelection records exactly what entered one prompt. The inspector uses the same value as chat, so its counts cannot drift from model input.

type Persona

type Persona struct {
	ID                string `json:"id"`
	Name              string `json:"name"`
	Description       string `json:"description"`
	ChatVoice         string `json:"chat_voice"`
	ReactionStyle     string `json:"reaction_style"`
	PromptSetID       string `json:"prompt_set_id"`
	DefaultFocusArea  string `json:"default_focus_area"`
	LoreMode          string `json:"lore_mode"`
	LoreCount         int    `json:"lore_count"`
	HasPortrait       bool   `json:"has_portrait"`
	PortraitUpdatedAt string `json:"portrait_updated_at,omitempty"`
	LastUsedAt        string `json:"last_used_at,omitempty"`
	CreatedAt         string `json:"created_at"`
	UpdatedAt         string `json:"updated_at"`
}

Persona is one saved preset. HasPortrait and PortraitUpdatedAt are derived from the same column: the timestamp doubles as an existence flag and as the cache-buster a tile URL needs when a portrait is replaced in place.

type PortableArchive

type PortableArchive struct {
	Schema          string                   `json:"schema"`
	Version         int                      `json:"version"`
	Persona         PortablePersona          `json:"persona"`
	Lore            []PortableLoreEntry      `json:"lore"`
	BehaviorProfile *PortableBehaviorProfile `json:"behavior_profile,omitempty"`
	Assets          *PortableAssets          `json:"assets,omitempty"`
	Portrait        []byte                   `json:"-"`
}

PortableArchive is the versioned, self-contained persona document carried by a .mhpersona ZIP. Runtime identifiers and timestamps are deliberately absent.

func DecodeArchive

func DecodeArchive(data []byte) (PortableArchive, error)

DecodeArchive parses and validates untrusted archive bytes without writing anything. Import orchestration can therefore resolve the behavior profile before committing a persona row.

type PortableAssets

type PortableAssets struct {
	Portrait string `json:"portrait,omitempty"`
}

PortableAssets names the bounded binary entries present in the archive.

type PortableBehaviorProfile

type PortableBehaviorProfile struct {
	ID      string `json:"id"`
	Name    string `json:"name,omitempty"`
	System  string `json:"system,omitempty"`
	Builtin bool   `json:"builtin"`
}

PortableBehaviorProfile embeds custom profile text but carries only the ID of a built-in profile, whose trusted local definition wins on import.

type PortableLoreEntry

type PortableLoreEntry struct {
	Text     string   `json:"text"`
	Keywords []string `json:"keywords"`
	Enabled  bool     `json:"enabled"`
}

PortableLoreEntry leaves identity and timestamps to the importing install.

type PortablePersona

type PortablePersona struct {
	Name             string `json:"name"`
	Description      string `json:"description"`
	ChatVoice        string `json:"chat_voice"`
	ReactionStyle    string `json:"reaction_style"`
	PromptSetID      string `json:"prompt_set_id"`
	DefaultFocusArea string `json:"default_focus_area"`
	LoreMode         string `json:"lore_mode"`
}

PortablePersona contains only user-authored and code-owned persona axes.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store owns persona rows and their portrait files.

func Open

func Open(dataDir string) (*Store, error)

Open borrows or creates the datastore for the persona domain.

func OpenWithDatabase

func OpenWithDatabase(database *dbstore.DB) (*Store, error)

OpenWithDatabase borrows the process-owned datastore.

func (*Store) Close

func (s *Store) Close() error

Close releases the handle only when this store opened it.

func (*Store) Create

func (s *Store) Create(ctx context.Context, draft Draft) (Persona, error)

Create stores a new persona. Unset fields resolve to the defaults rather than being rejected, so the "New persona" tile can create an editable row from a name alone.

func (*Store) CreateLore

func (s *Store) CreateLore(ctx context.Context, personaID string, draft LoreDraft) (LoreEntry, error)

CreateLore adds one entry while enforcing both the row and aggregate budgets.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, id string) error

Delete removes a persona and its portrait. Chat sessions keep their recorded persona_id: a past conversation should still read as the conversation it was, and callers resolve the dangling reference to the global axis values.

func (*Store) DeleteLore

func (s *Store) DeleteLore(ctx context.Context, personaID, loreID string) error

DeleteLore removes one entry.

func (*Store) DeletePortrait

func (s *Store) DeletePortrait(ctx context.Context, id string) (Persona, error)

DeletePortrait reverts a persona to its generated monogram.

func (*Store) Duplicate

func (s *Store) Duplicate(ctx context.Context, id string) (Persona, error)

Duplicate copies a persona, including its portrait file. Copying the picture matters: a duplicate that lost its portrait would look like a different persona in the grid, which is the opposite of what duplicating is for.

func (*Store) ExportArchive

func (s *Store) ExportArchive(
	ctx context.Context,
	id string,
	profile *chat.PromptSet,
) ([]byte, Persona, error)

ExportArchive gathers one persona and writes a deterministic portable archive. The optional behavior profile is supplied by the HTTP composition layer because prompt-set storage is not owned by this package.

func (*Store) Get

func (s *Store) Get(ctx context.Context, id string) (Persona, error)

Get returns one persona.

func (*Store) ImportPortable

func (s *Store) ImportPortable(
	ctx context.Context,
	portable PortableArchive,
	promptSetID string,
) (Persona, error)

ImportPortable commits a decoded archive under fresh persona and lore IDs. promptSetID is the local behavior-profile ID resolved by the composition layer; it may differ from the source installation's custom profile ID.

func (*Store) List

func (s *Store) List(ctx context.Context) ([]Persona, error)

List returns every persona, most recently used first, then by name. A persona that has never been used sorts after those that have, which puts the ones the user actually reaches for at the front of the grid.

func (*Store) ListLore

func (s *Store) ListLore(ctx context.Context, personaID string) ([]LoreEntry, error)

ListLore returns one persona's entries in stable authoring order.

func (*Store) MarkUsed

func (s *Store) MarkUsed(ctx context.Context, id string) (Persona, error)

MarkUsed records selection. This is what orders the grid, and it is deliberately not an update of updated_at: "last talked to" and "last edited" are different questions.

func (*Store) OpenPortrait

func (s *Store) OpenPortrait(ctx context.Context, id string) (*os.File, error)

OpenPortrait opens a stored portrait for serving.

func (*Store) PortraitDir

func (s *Store) PortraitDir() string

PortraitDir is where portraits live: under the app data directory, beside generated video thumbnails, and purgeable in one step.

func (*Store) SavePortrait

func (s *Store) SavePortrait(ctx context.Context, id string, data []byte) (Persona, error)

SavePortrait stores a portrait and stamps the row. The payload is decoded rather than trusted: a client claiming "this is an image" is not enough when the result is a file on disk that is later served back with an image type.

func (*Store) SelectLore

func (s *Store) SelectLore(ctx context.Context, personaID string, recentText []string) (LoreSelection, error)

SelectLore applies one persona's off/relevant/full policy to recent visible chat text. It never runs for Autopilot; persona lore may shape a reply, not an autonomous motion decision.

func (*Store) Update

func (s *Store) Update(ctx context.Context, id string, draft Draft) (Persona, error)

Update applies a partial change. The read and the write share one transaction so two tabs editing the same persona cannot interleave into a row that has neither one's values.

func (*Store) UpdateLore

func (s *Store) UpdateLore(ctx context.Context, personaID, loreID string, draft LoreDraft) (LoreEntry, error)

UpdateLore applies a partial entry update in one transaction.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL