render

package
v0.7.23 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package render holds the shared response-projection helpers for memini's API surfaces (REST and MCP): concise content rendering for progressive disclosure, compact display titles, and the content-identity hash clients use for injection dedupe. It is a projection layer only — it never touches ranking, filtering, or storage.

Index

Constants

View Source
const (
	// SearchMax is the concise rune cap for search results — REST
	// POST /v1/search with response_format="concise" and the MCP
	// memory_recall equivalent.
	SearchMax = 240
	// BriefingMax is the concise rune cap for briefing items
	// (GET /v1/namespaces/briefing?format=concise), matching the plugin
	// client's briefing render cap so server-side concise text is never
	// re-truncated on injection.
	BriefingMax = 280
	// TitleMax is the rune cap for child-rollup display titles — shorter than
	// the concise caps because the rollup is an index of what's under a
	// namespace, not the content itself.
	TitleMax = 60
)
View Source
const ItemOverheadTokens = 10

ItemOverheadTokens is the per-item overhead a server-enforced token budget charges on top of an item's shipped text: the render skeleton the client wraps around it (bullet prefix, score, labels, the [m:id] handle, a section header's amortized share). The server cannot see the client's actual template, so this is a deliberate small constant — an estimate, like ApproxTokens itself — shared by the /v1/search and briefing budgets.

Variables

This section is empty.

Functions

func ApproxTokens

func ApproxTokens(text string) int

ApproxTokens is the server half of the shared token estimator: a cheap ~0.75-tokens-per-word estimate, NOT a tokenizer. It replicates the plugin client's approxTokens (plugin/scripts/_shared.mjs) exactly — 0 for empty text, else max(1, ceil(words*4/3)) over the whitespace-split word count, where whitespace-only text (truthy for the client) floors to 1 — so a budget means the same thing on both ends of the wire. Documented as an estimate: budgets built on it bound token spend approximately, they do not guarantee an exact token count.

func Concise

func Concise(content, summary string, max int) (string, bool)

Concise returns the compact representation of a memory's text: the summary verbatim when one exists, the content verbatim when it already fits in max runes, and otherwise a boundary cut of the content with a "…" suffix. The boolean reports whether the text is a truncating cut of the content — false for a summary or for content that fits, which is how callers decide whether to mark content_truncated on the wire.

Cut rules, in order:

  1. Prefer a sentence boundary — '.', '!', or '?' followed by whitespace (space or newline) or end of text — when the latest one inside the window keeps at least 75% of it, so the concise text ends on a complete sentence without wasting most of the budget.
  2. Otherwise cut at the last space inside the window (trailing whitespace trimmed), so the cut never lands mid-word. A window whose following rune is whitespace already ends at a word end and is kept whole.
  3. A window with no space at all (one giant token) is hard-cut at exactly max runes — the legacy behavior.

Every decision — the cap, the scan, and the cut — counts runes, never bytes: deciding on bytes would append a spurious "…" to multi-byte content under the limit, and cutting on bytes could split a UTF-8 sequence.

func ContentHash

func ContentHash(content, summary string) string

ContentHash is the content-identity hash carried on search and briefing items: the first 16 hex chars of sha256 over the FULL stored content, falling back to the summary only when content is empty. It must match the plugin client's injectedIdentity recipe byte-for-byte (plugin/scripts/_shared.mjs — content first, summary only when content is empty/absent), and is always computed over the stored text, never a concise projection, so identity is stable across response formats.

func Title

func Title(content, summary string) string

Title derives a compact display title for index-style listings (the briefing's child rollup): the summary verbatim, else a TitleMax-rune boundary cut of the content.

Types

This section is empty.

Jump to

Keyboard shortcuts

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