storelink

package
v0.16.521 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 23 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 storelink is a runtime's connection to the store (internal/filestore, docs/hub/store.md): the hub's when the machine belongs to a hub that keeps one, otherwise a store inside this process, SQLite and a folder in the data folder. The model is the same either way: revisions in a database, contents by sha256, the folders on the machine a working copy. A store inside the process is the one a hub connected later takes over (docs/hub/store.md).

Index

Constants

View Source
const (
	// ModeAuto: the hub's store for a hub's machine whose hub has one; none for a runtime paired with a cluster's
	// agent (that cluster keeps its own data); a store inside the process for a runtime on its own.
	ModeAuto = "auto"
	// ModeHub: only the hub's store; a machine that is not a hub's, or a hub without one, syncs nothing.
	ModeHub = "hub"
	// ModeEmbedded: the store inside the process, whatever else there is.
	ModeEmbedded = "embedded"
	// ModeOff: nothing syncs; the runtime keeps its data as it always did.
	ModeOff = "off"
)

Modes of RUNTIME_STORE.

View Source
const (
	KindHub      = "hub"
	KindEmbedded = "embedded"
)

Kind of link.

View Source
const DefaultProfileState = ".local/state/profile-sync"

DefaultProfileState is the profile sync's state folder under HOME when the runtime names none (RUNTIME_PROFILE_STATE_DIR).

Variables

View Source
var ErrNoJournal = errors.New("the hub keeps no journal of the move")

ErrNoJournal is a store that keeps no journal of the move of the machine's data (docs/migrations): the store inside the runtime, or a hub of an older version.

View Source
var ErrNoSidebar = errors.New("the hub keeps no sidebar")

ErrNoSidebar is a hub that keeps no sidebar of the machine's person (its history is off, or it is older).

View Source
var ErrNotConnected = errors.New("the hub gave this machine no store session")

ErrNotConnected: the hub refuses this machine a store session (401, 403 or 423): it is not in a space of the hub yet (or was removed or switched off), or its clock is off. It is not a fault to repeat every few seconds: the session asks the hub again with growing pauses, and the loops that wait for the store wait for the connection (Link.Ready).

View Source
var ErrNotSyncing = errors.New("the collection is not being synced now")

ErrNotSyncing: no sync of the collection runs now (the store is not linked yet, or another runtime syncs the folder).

Functions

func Decide

func Decide(o Options) (string, string)

Decide is the kind of link the options call for, "" for none, and why.

func Handler

func Handler(h http.Handler) http.RoundTripper

Handler is a transport that answers every request with h inside the process: the store inside the runtime is spoken to over the same API as the hub's, without a socket.

func HubHasStore

func HubHasStore(ctx context.Context, hc *http.Client, base string) error

HubHasStore asks the hub's GET /api/capabilities whether it keeps a store. errNoStore when it answers without one.

func RequestSession

func RequestSession(ctx context.Context, hc *http.Client, m Machine, now time.Time) (hubproto.StoreSession, error)

RequestSession asks the hub for a store session (POST /agent/store), signed with the machine's key.

Types

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

Link is where the runtime's collections live.

func Open

func Open(o Options) (*Link, error)

Open opens the link the options call for; nil (and no error) when there is none.

func (*Link) Client

func (l *Link) Client(collection string) *filesync.Client

Client is a client of one of the link's collections.

func (*Link) Close

func (l *Link) Close()

Close closes the store inside the process.

func (*Link) Embedded

func (l *Link) Embedded() *filestore.Server

Embedded is the store inside the process, nil for the hub's (backup and the move into a hub reach it here).

func (*Link) HeadUnder

func (l *Link) HeadUnder(collection, rel string) (int64, error)

HeadUnder is the newest revision of the store the synced folder holds under rel (filesync.Agent.HeadUnder).

func (*Link) Kind

func (l *Link) Kind() string

Kind is KindHub or KindEmbedded.

func (*Link) MachineID

func (l *Link) MachineID() string

MachineID is the hub's id of this machine, "" for a store inside the process.

func (*Link) Person

func (l *Link) Person(ctx context.Context) (string, error)

Person is the name the hub gives this machine's person in the apps collection (hubproto.StoreSession.Person); "" for a store inside the runtime or a hub that names nobody.

func (*Link) PushNow

func (l *Link) PushNow(ctx context.Context, collection, rel string) error

PushNow sends what changed under rel of a synced folder to the store at once, ahead of the watcher and the periodic rescan: a project the page had to open from the machine is in the store for the next look.

func (*Link) Ready

func (l *Link) Ready(ctx context.Context, recheck time.Duration) error

Ready waits until the store answers that it is there: at once for the store inside the process; for the hub's, once its capabilities list the store. A hub without one is asked again every recheck, since it may be upgraded.

func (*Link) Report

Report tells the hub's journal how the move of this machine's data goes (hubproto.MigrationReport) and returns what a person asked of it since. It goes with the store session; a refused session is asked again once.

func (*Link) Sends

func (l *Link) Sends(collection, top string) bool

Sends says whether the files of a top folder of the synced collection may go to the store now: the store does not hold, or lists the folder. No sync running yet, a hub's collection sends nothing; another store sends.

func (*Link) Serves

func (l *Link) Serves(ctx context.Context, collection string) (bool, error)

Serves says whether the hub opens a collection to this machine (hubproto.StoreSession.Collections): an older hub does not know the newer kinds. A store inside the process serves every kind it knows.

func (*Link) Sidebar

Sidebar merges this machine's projects and favorites into its person's sidebar on the hub (hubproto.MigrationSidebar).

func (*Link) SyncFolder

func (l *Link) SyncFolder(ctx context.Context, collection string, root func() string)

SyncFolder keeps the folder root() names in step with a collection until ctx ends. The folder is asked again every minute: a library that moved (another workspace) is synced from where it is now, with a state of its own.

func (*Link) SyncProfile

func (l *Link) SyncProfile(ctx context.Context, p Profile)

SyncProfile keeps the person's profile in step with its room until ctx ends. One runtime of the machine syncs a HOME at a time; the others wait.

type Machine

type Machine struct {
	ID      string
	DialURL string
	Key     ed25519.PrivateKey
}

Machine is a hub's machine as its machine.json names it: who it is, where it dials and the key it proves itself with.

type Options

type Options struct {
	DataDir string
	Mode    string
	// Machine is the hub's machine this runtime runs on; nil for none.
	Machine *Machine
	// Paired: the runtime is one end of a pair with a cluster's agent (AGENT_SECRET_FILE, AGENT_CLUSTER_URL) and not a
	// hub's machine.
	Paired bool
	// Name is the machine's name in what a lost write leaves behind.
	Name string
	// Shared names folders several runtimes of the machine read (a team's library): one runtime syncs such a folder at
	// a time, and a file the store stops showing this machine stays there for the others.
	Shared func(dir string) bool
	// DB and Blobs name the drivers of a store inside the runtime (RUNTIME_STORE_DB, RUNTIME_STORE_BLOBS):
	// postgres://… or sqlite:///folder, and file:///folder or s3://…; empty is SQLite and blobs in store/ of the data
	// folder.
	DB    string
	Blobs string
	// HTTP is the client to the hub; nil for a plain one.
	HTTP *http.Client
	Log  *slog.Logger
	Now  func() time.Time
}

Options is what a runtime knows about where it runs.

type Profile

type Profile struct {
	Home string
	// State is the HOME-relative folder the sync keeps its staging, the edits that lost and its lock in: never synced
	// ("" = DefaultProfileState).
	State     string
	Codec     *filesync.ProfileCodec
	OnApplied func(rel string)
}

Profile is how a person's Claude profile syncs with its room in the hub (filestore.Profile): HOME is the folder, the codec seals with the room key, OnApplied hears every file another machine brought.

Jump to

Keyboard shortcuts

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