store

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 17 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 store is the hub's database, <data dir>/homie.db: MCP Gatekeeper's tables (accounts, people, passkeys, sessions, invites, OAuth, the admin-action audit) through package sqlitestore, and the hub's own tables next to them in the same file:

  • plugins: the installed plugins (what the plugin host runs, where each came from);
  • settings: the home's language, the home name typed or imported before the account exists, and the last access reset (an alert for the owner, review GK-5);
  • activity: every tool call, from the assistants, the admin and the CLI, with redacted arguments.

The home's name is the gatekeeper account's name once the account exists (Accounts().Rename); settings keep only the name that pre-fills the first setup.

Store embeds *sqlitestore.Store, so it is the gatekeeper's store.Store as well: auth, oauth, people and mcpguard take it as it is. The hub's tables join the gatekeeper's transactions (Tx; a write outside a Tx opens one). Every write of the hub's repositories runs in a transaction, so it takes the store's in-process write lock.

Conventions of the hub's repositories: times are INTEGER Unix milliseconds in UTC (0 means "never"); a get of something missing wraps core.ErrNotFound, a duplicate id wraps core.ErrConflict; returned slices are the caller's.

ImportV01 copies what can move from a v0.1 homed.db (docs: the step-2 plan §3.3): the plugins, the language and the home name. Passkeys, sessions, keys and people cannot move (the passkeys' relying party changes with the tunnel).

Index

Constants

View Source
const DefaultLanguage = "ru"

DefaultLanguage is the language of a home that never chose one.

View Source
const V01Suffix = ".v0.1"

V01Suffix is added to the v0.1 database once ImportV01 copied it: homed.db becomes homed.db.v0.1, kept (0600) so the old tool history stays readable.

Variables

This section is empty.

Functions

This section is empty.

Types

type Activity

type Activity interface {
	// Append stores records in order, in one transaction, and returns them with ID set; a zero At is now.
	Append(ctx context.Context, recs []ActivityRecord) ([]ActivityRecord, error)
	// Query returns matching records, newest (highest ID) first. When it returns Limit records, the next page is the
	// same filter with BeforeID set to the last record's ID.
	Query(ctx context.Context, f ActivityFilter) ([]ActivityRecord, error)
	// Get returns one record by id.
	Get(ctx context.Context, id int64) (ActivityRecord, error)
	// Prune deletes records older than before and returns how many it deleted.
	Prune(ctx context.Context, before time.Time) (int64, error)
}

Activity stores the tool-call log. The hub's writer (internal/audit) batches into Append, so a call never waits for the disk.

type ActivityFilter

type ActivityFilter struct {
	PersonID string
	PluginID string
	Tool     string
	Via      []string // any of these; empty matches all
	Status   ActivityStatus
	Since    time.Time // At >= Since
	Until    time.Time // At < Until
	BeforeID int64     // ID < BeforeID: the cursor of the next page; 0 starts at the newest
	Limit    int       // page size; capped at 200, 50 when 0
}

ActivityFilter selects records. Zero fields match everything.

type ActivityRecord

type ActivityRecord struct {
	ID       int64 // assigned by Append, strictly increasing; the page cursor
	At       time.Time
	PersonID string          // the gatekeeper person id; empty for the CLI
	Person   string          // the display name at the time; kept after the person is gone
	Via      string          // "chatgpt", "claude", "admin" or "cli"
	Tool     string          // e.g. "tv_power_on"
	PluginID string          // the tool's plugin
	Args     json.RawMessage // redacted arguments (audit.Redact); may be nil
	OK       bool
	Error    string // why it failed, human English; never secrets
	Duration time.Duration
}

ActivityRecord is one tool call, as stored.

type ActivityStatus

type ActivityStatus string

ActivityStatus filters by outcome.

const (
	// ActivityAny matches every record.
	ActivityAny ActivityStatus = ""
	// ActivityOK matches successes only.
	ActivityOK ActivityStatus = "ok"
	// ActivityFailed matches failures only.
	ActivityFailed ActivityStatus = "failed"
)

type HomeSettings

type HomeSettings struct {
	// Language is the home's default UI language, "ru" or "en".
	Language string
	// HomeName pre-fills the first setup: imported from v0.1 or kept from before the account existed. Once the account
	// exists, its name (core.Account.Name) is the home's name and this one is not read.
	HomeName string
	// AccessResetAt is when `homed admin reset-access` last ran (review GK-5: an alert the owner sees); zero: never.
	AccessResetAt time.Time
	// AccessResetBy names the program that asked on the admin socket, e.g. "/usr/bin/x (pid 4242)"; "" when unknown.
	AccessResetBy string
	UpdatedAt     time.Time
}

HomeSettings is the one row of home settings.

type ImportResult

type ImportResult struct {
	// Imported is true when this call copied the data; false when it ran before or there was no old database.
	Imported bool
	// Plugins is how many plugins this call copied; a plugin whose id exists already is left alone.
	Plugins int
	// Language is true when the home's language was copied.
	Language bool
	// HomeName is true when the old home name was kept to pre-fill the first setup (only while no account exists).
	HomeName bool
	// Renamed is where this call moved the old database; "" when it moved nothing.
	Renamed string
}

ImportResult says what ImportV01 did.

type Options

type Options struct {
	// Path is the database file, <data dir>/homie.db. It is created 0600 in a 0700 directory when missing.
	Path string
	// Clock stamps the hub's rows, the audit ids and the migrations; nil is time.Now.
	Clock core.Clock
	// Logger receives the migration log and file-mode warnings; nil discards them.
	Logger *slog.Logger
}

Options configures Open.

type Plugin

type Plugin struct {
	ID              string // ^[a-z][a-z0-9]{1,15}$
	Source          PluginSource
	Repo            string   // "owner/name" for PluginGitHub, e.g. "devXpro/homie-tv"
	Version         string   // installed release, e.g. "0.2.0"; empty for PluginLocal
	PreviousVersion string   // the release kept for rollback; empty when none
	Command         []string // executable (absolute path) and arguments, e.g. [".../bin/0.2.0/homie-tv", "serve"]
	Enabled         bool     // disabled plugins are not started and their tools are not listed
	InstalledAt     time.Time
	UpdatedAt       time.Time
}

Plugin is one installed plugin: what the plugin host needs to run it (plugins.Spec) and where it came from.

type PluginSource

type PluginSource string

PluginSource says where a plugin came from.

const (
	// PluginGitHub was installed from a GitHub release.
	PluginGitHub PluginSource = "github"
	// PluginLocal is a command on this machine, added with the CLI (development).
	PluginLocal PluginSource = "local"
)

type Plugins

type Plugins interface {
	// Get returns one plugin by id.
	Get(ctx context.Context, id string) (Plugin, error)
	// List returns every plugin, by id.
	List(ctx context.Context) ([]Plugin, error)
	// Create stores a newly installed plugin; a taken id wraps core.ErrConflict. Zero times are set to now.
	Create(ctx context.Context, p Plugin) error
	// Update replaces every field but ID and InstalledAt, and sets UpdatedAt.
	Update(ctx context.Context, p Plugin) error
	// Delete removes one plugin's row; its files are the installer's business.
	Delete(ctx context.Context, id string) error
}

Plugins stores the installed plugins.

type Settings

type Settings interface {
	// Get returns the settings; before the first Put it returns HomeSettings{Language: DefaultLanguage}.
	Get(ctx context.Context) (HomeSettings, error)
	// Put replaces the settings and sets UpdatedAt.
	Put(ctx context.Context, hs HomeSettings) error
	// Update reads the settings, lets fn change them and stores them, in one transaction.
	Update(ctx context.Context, fn func(*HomeSettings) error) error
}

Settings stores the HomeSettings row.

type Store

type Store struct {
	*sqlitestore.Store
	// contains filtered or unexported fields
}

Store is homie.db: the gatekeeper's store plus the hub's repositories. It is safe for concurrent use.

func Open

func Open(ctx context.Context, o Options) (*Store, error)

Open opens (creating it when missing) the database, applies the gatekeeper's and the hub's migrations and returns the store. It refuses a database written by a newer homed.

func (*Store) Activity

func (s *Store) Activity() Activity

Activity returns the tool-call log.

func (*Store) Audit

func (s *Store) Audit() gkstore.AuditStore

Audit is the gatekeeper's audit store with every entry stamped with its actor's name (package actorname), whichever package writes it, so the audit API can name people who are gone.

func (*Store) ImportV01

func (s *Store) ImportV01(ctx context.Context, oldPath string) (ImportResult, error)

ImportV01 copies what can move from the v0.1 database at oldPath (<data dir>/homed.db) into s:

  • the plugins, rows as they are: their commands point into the data dir (or at a local binary) and keep working, and the plugins' own data (a TV's pairing) is outside the database anyway;
  • the language;
  • the home name, which pre-fills the first setup and then becomes the account's name; when the account exists already, its name is the home's and the old one is dropped.

People, passkeys, sessions, keys, connections and the old audit do not move. The mark of the import is written in the same transaction as the data, and the old file is renamed to oldPath+V01Suffix only after that transaction committed: a crash at any point leaves a state the next call finishes, and a call after the import is a no-op. homed calls it at every start.

func (*Store) Plugins

func (s *Store) Plugins() Plugins

Plugins returns the installed plugins.

func (*Store) Settings

func (s *Store) Settings() Settings

Settings returns the home settings.

Jump to

Keyboard shortcuts

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