perceive

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: AGPL-3.0 Imports: 9 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 perceive turns Sessions (event streams) into Experiences. Deterministic facts are parsed from events directly; only semantic context attributes go to the LLM (ADR-0004: 決定的にパースできるものは LLMに聞かない). Perception is deferred and replayable (ADR-0004/0005).

Index

Constants

This section is empty.

Variables

View Source
var SemanticKeys = []string{"lang", "framework", "topic", "size"}

LLM-extracted context keys (SCHEMA.md R2). cap/model/provider are deterministic and never asked of the model.

Functions

func PerceiveTaskContext

func PerceiveTaskContext(extractor Extractor, intent string, vocab map[string][]string) (map[string]string, error)

PerceiveTaskContext extracts Context attribute tokens from a task description before anything has happened — the pre-execution counterpart to perceiveSession (PERCEPTION_ENGINE.md: Task Perception). It shares the extractor, SemanticKeys, and normalizeSemantic guarantee session-based perception uses; only the source text handed to the model differs (a task description instead of a session's events). A nil extractor mirrors perceiveSession's own nil-Extractor path: no semantic context, no error.

The result stops at normalizeSemantic's form (TrimSpace+ToLower) and does not additionally apply core.CanonValue. perceiveSession stores Context the same way — CanonValue is first applied later, uniformly, at Scope generation (core.Experience.Tokens → core.CanonToken; SCHEMA.md D5's "known drift", still open). Doing it here would make this the one SemanticKeys reader that disagrees with capVocab, Store.KnownValues, and stored Context about what "normalized" means, while the caller already owns a CanonToken call for the deterministic cap/size tokens (ADR-0036 Decision 1, decisionTokens) — folding lang/framework/topic/size into that same call keeps one normalization boundary instead of two.

func Vocab

func Vocab(s *store.Store) (map[string][]string, error)

capVocab picks, per semantic key, the vocabLimit values most worth showing the extraction prompt. SCHEMA.md D5 hands vocabulary to the prompt so the model converges spelling variants ("axum"/"Axum"/ "axum-web") onto one form instead of inventing a new one each time.

A value is worth protecting once it has recurred: a single occurrence cannot yet have drifted into variants, so the value most in need of convergence is the one reused across the most distinct sessions — frequency is therefore the primary ranking signal. Recency breaks ties in favor of the spelling actually in current use, so a value dormant for a long time does not permanently hold a slot over one the user is actively naming today. The value string itself is the final tiebreaker, making the ranking independent of Go's randomized map order (ADR-0011: 判断は数学 — the derivation must be deterministic).

Frequency counts distinct SESSIONS, not experience rows: a session's preference experiences (ADR-0003) copy the execution experience's Context verbatim (perceiveSession below), so counting rows would let one session with several preferences outrank several sessions that each used a value once — the opposite of "recurred across real occurrences". Vocab is the vocabulary both perceptions hand their extractor: the same ranking, the same cap, read from the same current experiences. Task Perception (ADR-0036) has to see this exact set, not its own slice of Store.KnownValues — otherwise a saturated key would show the two callers different spellings, and ADR-0036 Decision 2e's premise ("both go through the same extractor, the same vocabulary, the same schema, so they converge systematically") would be false in exactly the case where it matters. A divergence between T_pre and T_post is supposed to be readable as the extractor's calibration; it must not also be able to mean "they were shown different words".

Types

type Extractor

type Extractor interface {
	ExtractContext(events []*store.Event, vocab map[string][]string) (map[string]string, error)
	// ExtractTaskContext reads intent — a task description, not yet an
	// event — through the same schema/prompt/validation guarantee
	// ExtractContext gives session-based extraction (ADR-0036 Decision
	// 2c). It never synthesizes a pseudo-event to reuse ExtractContext's
	// signature: a task description is not an occurrence, and shaping it
	// into one would blur the ledger's meaning (ADR-0036 Consequences).
	ExtractTaskContext(intent string, vocab map[string][]string) (map[string]string, error)
	Name() string // extractor_model, e.g. "qwen3:8b"
}

Extractor extracts semantic context attributes either from a session's events (after execution) or from a task description (before execution — PERCEPTION_ENGINE.md Task Perception, ADR-0011 Decision 3). Both read the same SemanticKeys and the same known-vocabulary discipline (SCHEMA.md D5); vocab maps each semantic key to values already known to Tomobit, handed to the prompt to prevent vocabulary drift.

type MLXLM

type MLXLM struct {
	URL   string // default http://localhost:8080
	Model string // HF repo id, e.g. "mlx-community/Qwen3-8B-4bit"
}

MLXLM extracts semantic context attributes via mlx_lm.server's OpenAI- compatible endpoint (ADR-0029). mlx-lm has no structured output (`response_format`/`json_schema` are unimplemented, confirmed by reading mlx_lm/server.py), so the shape guarantee Ollama gets from `format` here falls to mlxShapeBlock in the prompt plus parseMLXContent's validation below (ADR-0029 Decision 2). Field SEMANTICS stay shared with Ollama via extractSystem (ADR-0005) — only the shape instruction differs per backend.

func (*MLXLM) ExtractContext

func (m *MLXLM) ExtractContext(events []*store.Event, vocab map[string][]string) (map[string]string, error)

func (*MLXLM) ExtractTaskContext

func (m *MLXLM) ExtractTaskContext(intent string, vocab map[string][]string) (map[string]string, error)

ExtractTaskContext is ExtractContext's pre-execution counterpart (ADR-0036 Decision 2c): same schema, prompt, and vocabulary — only taskSection's text differs from eventsSection's.

func (*MLXLM) Name

func (m *MLXLM) Name() string

type Ollama

type Ollama struct {
	URL   string // default http://localhost:11434
	Model string // e.g. "qwen3:8b"
}

Ollama extracts semantic context attributes with a local model.

ADR-0005: the JSON schema passed via `format` guarantees SHAPE only — its descriptions never reach the model (dropped in GBNF conversion). All field SEMANTICS therefore live in the system prompt below. When adding a field, update BOTH, and bump extractor_ver.

func (*Ollama) ExtractContext

func (o *Ollama) ExtractContext(events []*store.Event, vocab map[string][]string) (map[string]string, error)

func (*Ollama) ExtractTaskContext

func (o *Ollama) ExtractTaskContext(intent string, vocab map[string][]string) (map[string]string, error)

ExtractTaskContext is ExtractContext's pre-execution counterpart (ADR-0036 Decision 2c): same schema, prompt, and vocabulary — only taskSection's text differs from eventsSection's.

func (*Ollama) Name

func (o *Ollama) Name() string

type Perceiver

type Perceiver struct {
	Store     *store.Store
	Extractor Extractor
	Ver       int // extractor_ver: bump when prompt/schema changes
}

Perceiver runs deferred perception over pending sessions.

func (*Perceiver) Run

func (p *Perceiver) Run() ([]*core.Experience, error)

Run perceives every pending session and returns the new experiences. A failing session aborts the run; already-perceived sessions are untouched, the rest stay pending (deferred perception — nothing lost).

Jump to

Keyboard shortcuts

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