Documentation
¶
Overview ¶
Package chatstore is the on-disk store behind `ppz chat`: per-identity chat history, the list of added pipes, and read markers — one JSON file per conversation window under $PPZ_HOME/chat/<handle>/. JetStream stays the source of truth for received messages; this store is authoritative only for the bits it can't hand back — your outbound sends and your read position.
Windows are loaded into memory on Open, mutated there (with in-memory dedup), and written back on Flush (atomic temp+rename) — so the launch replay burst is O(1) per message, not a file rewrite each time.
Index ¶
- Constants
- type Message
- type Store
- func (s *Store) AddPipe(name, label string) error
- func (s *Store) Flush() error
- func (s *Store) Ingest(kind, name, label string, m Message) (bool, error)
- func (s *Store) MarkRead(kind, name string) error
- func (s *Store) Messages(kind, name string) ([]Message, error)
- func (s *Store) Migrate(fromKind, toKind, name string) error
- func (s *Store) RemovePipe(name string) error
- func (s *Store) Unread(kind, name string) (int, error)
- func (s *Store) Windows() ([]Window, error)
- type Window
Constants ¶
const ( KindAgent = "agent" KindSource = "source" // message-kind source: a bare inbox (human/service) KindPipe = "pipe" )
Window kinds. A window is uniquely identified by (Kind, Name): an agent DM keyed by the counterparty handle, or an uncollared pipe keyed by its target.
const ( DirIn = "in" // received DirOut = "out" // sent by me (never replayable from the wire) )
Message directions.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Message ¶
type Message struct {
ID string `json:"id"`
Dir string `json:"dir"`
Sender string `json:"sender"`
Subject string `json:"subject,omitempty"`
Payload string `json:"payload"`
CreatedAt string `json:"created_at"`
}
Message is one stored envelope. CreatedAt is the daemon's RFC3339-UTC stamp, which sorts lexically.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a per-identity chat store rooted at <home>/chat/<handle>/.
func Open ¶
Open resolves (and creates) <home>/chat/<handle>/ and loads any existing window files into memory.
func (*Store) AddPipe ¶
AddPipe creates an (initially empty) pipe window so it shows in the roster before any message arrives.
func (*Store) Ingest ¶
Ingest records a message in the (kind, name) window, creating the window if needed. Idempotent by Message.ID. Returns whether it was newly added. The write is buffered in memory; call Flush to persist.
func (*Store) MarkRead ¶
MarkRead advances the window's read marker to its newest message (unread→0).
func (*Store) Migrate ¶ added in v0.54.0
Migrate re-keys a window from fromKind to toKind (same name): a simple re-key when the target is absent, or a merge (dedup by id, keeping the later read marker) when it exists. The old file is deleted; the target is written on the next Flush. Used when chat learns a handle it first saw as an agent DM is actually a message source, so a restart can't rebuild two windows for one counterparty.
func (*Store) RemovePipe ¶
RemovePipe forgets a pipe window and deletes its file.