targetmem

package
v0.167.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package targetmem stores per-target facts across PromptZero sessions. When a scan, detect, or RX tool produces a target identifier (BSSID, card UID, RF frequency+protocol), the agent can record what it learned about that target and recall those facts on future sessions.

Backing store: SQLite. Same database file as the audit log would be conceptually clean but keeps migration simpler to separate for now; targets live in ~/.promptzero/targetmem.db. Schema is key/value per target identifier so operators can attach arbitrary JSON without schema migrations.

Index

Constants

View Source
const (
	KindBSSID    = "bssid"
	KindNFCUID   = "nfc_uid"
	KindRFIDData = "rfid_data"
	KindSubGHz   = "subghz"
	KindIButton  = "ibutton"
)

Known target kinds. Operators / tools are free to introduce new kinds — the store accepts any string — but these constants cover the common cases.

View Source
const MaxRecent = 1000

MaxRecent caps the per-call row count returned by Recent. The targets table grows without bound across sessions; a Recent(1000000) call (operator typo, malicious LLM tool call) would tie up SQLite and serialise a multi-MB JSON. 1000 is generous for any reasonable recall flow.

Variables

This section is empty.

Functions

func DefaultPath

func DefaultPath() (string, error)

DefaultPath returns ~/.promptzero/targetmem.db.

Types

type Store

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

Store is the persistent target memory. Safe for concurrent use; a single SQLite connection is serialised internally.

func Open

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

Open creates or opens the target-memory store at path. The parent directory is created if missing. Schema migrations run idempotently on every open so a fresh install and an existing db reach the same state.

func (*Store) Close

func (s *Store) Close() error

Close releases the database connection.

func (*Store) Forget

func (s *Store) Forget(identifier, kind string) error

Forget deletes a target. Safe to call on a non-existent target — returns nil. Intended for /targets forget <id> in the REPL.

func (*Store) Lookup

func (s *Store) Lookup(identifier, kind string) (Target, bool, error)

Lookup returns a target by identifier+kind or (zero, false) when absent. Case-sensitive — BSSIDs are normalised lowercase by convention at the call site, not the store.

func (*Store) Recent

func (s *Store) Recent(n int) ([]Target, error)

Recent returns the N most recently observed targets, newest first. Useful for the /targets REPL command and for the agent's session- start known-targets context block. n is bounded by MaxRecent so an LLM tool call asking for 1000000 can't push the entire targets table into a JSON tool-result.

func (*Store) Remember

func (s *Store) Remember(t Target) error

Remember upserts a target. When the identifier+kind already exists, Facts is overwritten and LastSeen bumps; FirstSeen is preserved so the original discovery timestamp survives across re-observations. Passing an empty identifier is rejected to keep the primary key clean.

type Target

type Target struct {
	Identifier string    `json:"identifier"`
	Kind       string    `json:"kind"` // "bssid" / "nfc_uid" / "rfid_data" / "subghz" / other
	Facts      any       `json:"facts,omitempty"`
	FirstSeen  time.Time `json:"first_seen"`
	LastSeen   time.Time `json:"last_seen"`
}

Target is one remembered target row. Identifier is the stable key (BSSID, card UID hex, freq+protocol tuple); Kind describes what kind of identifier it is so the model knows how to read it.

Jump to

Keyboard shortcuts

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