memory

package
v0.107.6 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const ScopeLimit = 500

Variables

This section is empty.

Functions

func ProjectHash added in v0.107.0

func ProjectHash(workdir string) (string, error)

func PromptBlock

func PromptBlock(scopes ...Scope) string

func ReadOnlyPromptBlock added in v0.107.6

func ReadOnlyPromptBlock(scopes ...Scope) string

ReadOnlyPromptBlock injects saved entries for hosts that no longer offer remember/forget.

Types

type BatchArgs added in v0.107.0

type BatchArgs struct {
	Workdir        string `json:"workdir,omitempty"`
	ConversationID string `json:"conversationId,omitempty"`
	Trigger        string `json:"trigger,omitempty"`
	Model          string `json:"model,omitempty"`
	LocalDate      string `json:"localDate,omitempty"`
	DailyAppend    *struct {
		Bullet string `json:"bullet"`
	} `json:"dailyAppend,omitempty"`
	Decisions []Decision `json:"decisions,omitempty"`
}

type BatchResponse added in v0.107.0

type BatchResponse struct {
	Created        []string       `json:"created"`
	Updated        []string       `json:"updated"`
	Deleted        []string       `json:"deleted"`
	Warnings       []string       `json:"warnings"`
	WarningDetails []BatchWarning `json:"warningDetails"`
}

type BatchWarning added in v0.107.0

type BatchWarning struct {
	Code          string `json:"code"`
	Message       string `json:"message"`
	Slug          string `json:"slug,omitempty"`
	Op            string `json:"op,omitempty"`
	GroupID       string `json:"groupId,omitempty"`
	DecisionIndex int    `json:"decisionIndex"`
	Details       any    `json:"details"`
}

type Decision added in v0.107.0

type Decision struct {
	Op            string              `json:"op"`
	Slug          string              `json:"slug"`
	Scope         string              `json:"scope,omitempty"`
	WorkdirHash   string              `json:"workdirHash,omitempty"`
	MemoryType    string              `json:"memoryType,omitempty"`
	Description   *string             `json:"description,omitempty"`
	Body          *string             `json:"body,omitempty"`
	Mode          string              `json:"mode,omitempty"`
	Reason        string              `json:"reason,omitempty"`
	GroupID       string              `json:"groupId,omitempty"`
	Evidence      *Evidence           `json:"evidence,omitempty"`
	Preconditions []EntryPrecondition `json:"preconditions,omitempty"`
}

type DeleteArgs added in v0.107.0

type DeleteArgs struct {
	ReadArgs
	Actor          string `json:"actor,omitempty"`
	Reason         string `json:"reason,omitempty"`
	ConversationID string `json:"conversationId,omitempty"`
	Model          string `json:"model,omitempty"`
}

type Entry

type Entry struct {
	N    int
	Text string
	Done bool
}

type EntryPrecondition added in v0.107.6

type EntryPrecondition struct {
	ReadArgs
	Body        string `json:"body"`
	Description string `json:"description"`
}

type Evidence added in v0.107.0

type Evidence struct {
	Confidence     string   `json:"confidence,omitempty"`
	SourceQuote    string   `json:"sourceQuote,omitempty"`
	Reasoning      string   `json:"reasoning,omitempty"`
	Aliases        []string `json:"aliases,omitempty"`
	ConflictsWith  []string `json:"conflictsWith,omitempty"`
	Supersedes     string   `json:"supersedes,omitempty"`
	OverrideReject string   `json:"overrideReject,omitempty"`
}

type ListArgs added in v0.107.0

type ListArgs struct {
	Scope              string `json:"scope,omitempty"`
	Workdir            string `json:"workdir,omitempty"`
	IncludeAllProjects bool   `json:"includeAllProjects,omitempty"`
	MemoryType         string `json:"memoryType,omitempty"`
	IncludeDaily       bool   `json:"includeDaily,omitempty"`
	Limit              int    `json:"limit,omitempty"`
	Offset             int    `json:"offset,omitempty"`
}

type ListResponse added in v0.107.0

type ListResponse struct {
	Entries   []Meta `json:"entries"`
	Truncated bool   `json:"truncated"`
	Quota     Quota  `json:"quota"`
}

type Meta added in v0.107.0

type Meta struct {
	Slug        string  `json:"slug"`
	Scope       string  `json:"scope"`
	WorkdirHash string  `json:"workdirHash"`
	WorkdirPath string  `json:"workdirPath,omitempty"`
	MemoryType  string  `json:"memoryType"`
	Description string  `json:"description"`
	Headline    string  `json:"headline"`
	DateLocal   *string `json:"dateLocal"`
	CreatedAt   int64   `json:"createdAt"`
	UpdatedAt   int64   `json:"updatedAt"`
	AppendCount int     `json:"appendCount"`
	Archived    bool    `json:"archived"`
	Unreviewed  bool    `json:"unreviewed"`
	Confidence  string  `json:"confidence"`
	FileSize    int64   `json:"fileSize"`
}

type MutationResponse added in v0.107.0

type MutationResponse struct {
	Slug              string  `json:"slug"`
	Scope             string  `json:"scope"`
	Created           bool    `json:"created"`
	Updated           bool    `json:"updated"`
	Deleted           bool    `json:"deleted"`
	IndexUpdated      bool    `json:"indexUpdated"`
	Warning           *string `json:"warning"`
	AppliedConfidence string  `json:"appliedConfidence,omitempty"`
	AutoDowngraded    *bool   `json:"autoDowngraded,omitempty"`
}

type OrganizeRun added in v0.107.0

type OrganizeRun map[string]any

OrganizeRun retains optional report fields without rewriting old report versions.

type OverviewResponse added in v0.107.0

type OverviewResponse struct {
	User        []Meta  `json:"user"`
	Project     []Meta  `json:"project"`
	Global      []Meta  `json:"global"`
	RecentDays  []Meta  `json:"recentDays"`
	Root        string  `json:"root"`
	WorkdirHash *string `json:"workdirHash"`
}

type Quota added in v0.107.0

type Quota struct {
	Used        int          `json:"used"`
	Limit       int          `json:"limit"`
	ScopeQuotas []ScopeQuota `json:"scopeQuotas"`
}

type QuotaSummaryResponse added in v0.107.0

type QuotaSummaryResponse struct {
	Scopes []ScopeQuota `json:"scopes"`
}

type ReadArgs added in v0.107.0

type ReadArgs struct {
	Slug        string `json:"slug"`
	Scope       string `json:"scope,omitempty"`
	Workdir     string `json:"workdir,omitempty"`
	WorkdirHash string `json:"workdirHash,omitempty"`
	Offset      int    `json:"offset,omitempty"`
	Length      int    `json:"length,omitempty"`
}

type ReadMeta added in v0.107.0

type ReadMeta struct {
	Unreviewed bool   `json:"unreviewed"`
	Confidence string `json:"confidence"`
	Source     any    `json:"source"`
	CreatedAt  int64  `json:"createdAt"`
	UpdatedAt  int64  `json:"updatedAt"`
	Archived   bool   `json:"archived"`
}

type ReadResponse added in v0.107.0

type ReadResponse struct {
	Slug        string     `json:"slug"`
	Scope       string     `json:"scope"`
	MemoryType  string     `json:"memoryType"`
	Description string     `json:"description"`
	Headline    string     `json:"headline"`
	Body        string     `json:"body"`
	TotalLines  int        `json:"totalLines"`
	Window      ReadWindow `json:"window"`
	Meta        ReadMeta   `json:"meta"`
}

type ReadWindow added in v0.107.0

type ReadWindow struct {
	Offset    int  `json:"offset"`
	Length    int  `json:"length"`
	Truncated bool `json:"truncated"`
}

type Rejection added in v0.107.0

type Rejection struct {
	Slug        string `json:"slug"`
	Scope       string `json:"scope"`
	WorkdirHash string `json:"workdirHash"`
	RejectedAt  int64  `json:"rejectedAt"`
	Actor       string `json:"actor"`
	Reason      string `json:"reason,omitempty"`
}

type Scope

type Scope struct {
	Path string
	Name string
}

func Installation

func Installation() Scope

func Session

func Session(id string) Scope

func (Scope) Entries

func (s Scope) Entries() []Entry

func (Scope) Forget

func (s Scope) Forget(n int) error

func (Scope) ReadEntries added in v0.107.6

func (s Scope) ReadEntries() ([]Entry, error)

ReadEntries is Entries with the read error kept; a missing file is empty.

func (Scope) Remember

func (s Scope) Remember(text string) error

type ScopeQuota added in v0.107.0

type ScopeQuota struct {
	Scope                   string   `json:"scope"`
	WorkdirHash             string   `json:"workdirHash"`
	Used                    int      `json:"used"`
	Limit                   int      `json:"limit"`
	Headroom                int      `json:"headroom"`
	Archived                int      `json:"archivedCount"`
	UnreviewedCount         int      `json:"unreviewedCount"`
	OldestUnreviewedAgeDays *float64 `json:"oldestUnreviewedAgeDays"`
}

type SearchArgs added in v0.107.0

type SearchArgs struct {
	Query            string `json:"query"`
	Scope            string `json:"scope,omitempty"`
	Workdir          string `json:"workdir,omitempty"`
	MemoryType       string `json:"memoryType,omitempty"`
	Limit            int    `json:"limit,omitempty"`
	IncludeHistory   bool   `json:"includeHistory,omitempty"`
	HistorySince     int64  `json:"historySince,omitempty"`
	HistoryUntil     int64  `json:"historyUntil,omitempty"`
	HistoryDateLocal string `json:"historyDateLocal,omitempty"`
	HistoryTimeMode  string `json:"historyTimeMode,omitempty"`
}

type SearchMatch added in v0.107.0

type SearchMatch struct {
	Slug        string   `json:"slug"`
	Scope       string   `json:"scope"`
	WorkdirHash string   `json:"workdirHash,omitempty"`
	MemoryType  string   `json:"memoryType"`
	Description string   `json:"description"`
	Headline    string   `json:"headline"`
	Snippet     string   `json:"snippet"`
	Score       float64  `json:"score"`
	RawScore    *float64 `json:"rawScore"`
	AgeDays     *float64 `json:"ageDays"`
	Unreviewed  bool     `json:"unreviewed"`
	Confidence  string   `json:"confidence"`
}

type SearchResponse added in v0.107.0

type SearchResponse struct {
	Matches        []SearchMatch `json:"matches"`
	HistoryMatches []any         `json:"historyMatches"`
	UsedFallback   bool          `json:"usedFallback"`
}

type Store added in v0.107.0

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

func OpenStore added in v0.107.0

func OpenStore(root string) (*Store, error)

func (*Store) Accept added in v0.107.0

func (s *Store) Accept(args ReadArgs) (MutationResponse, error)

func (*Store) ApplyBatch added in v0.107.0

func (s *Store) ApplyBatch(args BatchArgs) (BatchResponse, error)

func (*Store) ApplyExtractionBatch added in v0.107.6

func (s *Store) ApplyExtractionBatch(args BatchArgs, epoch uint64) (BatchResponse, error)

ApplyExtractionBatch discards plans from before a wipe under the same lock that protects both the wipe and every batch mutation.

func (*Store) CancelOrganizeRun added in v0.107.0

func (s *Store) CancelOrganizeRun(id, warning string) (OrganizeRun, bool, error)

CancelOrganizeRun changes only a reviewable run. Once apply ownership has been claimed, cancellation leaves that state untouched.

func (*Store) CancelOrganizeRunOwned added in v0.107.0

func (s *Store) CancelOrganizeRunOwned(id string, epoch uint64, executor, warning string) (OrganizeRun, bool, error)

CancelOrganizeRunOwned cancels only when the caller still owns the run.

func (*Store) ClaimOrganizeDue added in v0.107.0

func (s *Store) ClaimOrganizeDue() (map[string]any, error)

func (*Store) ClaimOrganizeRunApply added in v0.107.0

func (s *Store) ClaimOrganizeRunApply(id string) (OrganizeRun, bool, error)

ClaimOrganizeRunApply persists ownership before any batch side effects. An interrupted applying run is not replayed automatically.

func (*Store) ClearOrganizeHistory added in v0.107.0

func (s *Store) ClearOrganizeHistory() (map[string]any, error)

func (*Store) CreateOrganizeRun added in v0.107.0

func (s *Store) CreateOrganizeRun(run OrganizeRun) (OrganizeRun, error)

func (*Store) Delete added in v0.107.0

func (s *Store) Delete(args DeleteArgs) (MutationResponse, error)

func (*Store) DeleteProject added in v0.107.0

func (s *Store) DeleteProject(workdir, actor, reason string) (map[string]any, error)

func (*Store) Dispatch added in v0.107.0

func (s *Store) Dispatch(command string, raw json.RawMessage) (any, error)

Dispatch executes the explicitly supported native memory command set.

func (*Store) DropUnjudged added in v0.107.6

func (s *Store) DropUnjudged(session string) error

DropUnjudged forgets a session's held messages, for a deleted session.

func (*Store) HoldUnjudged added in v0.107.6

func (s *Store) HoldUnjudged(session string, epoch uint64, msgs []UnjudgedMessage) error

HoldUnjudged adds messages to a session's unjudged list, keeping the newest maxUnjudgedPerSession and one entry per ID. Messages read before a wipe (epoch is not the current WipeEpoch) are dropped.

func (*Store) ImportMarkdown added in v0.107.6

func (s *Store) ImportMarkdown(scope Scope) (int, error)

ImportMarkdown copies the open remember/forget markdown entries into unreviewed global user memory, once per store. Later edits to the file are not followed: it stays in place for hosts that still read it (TUI, non-interactive kn), and the store is the backend's only writable memory. Entries the store rejects are skipped and reported in the returned error; a read or I/O failure leaves the import unfinished so the next start retries.

Each entry is claimed as pending before its write and recorded as done after it. A pending entry found on the next start is kept if its write landed and written again if not; deleting a pending entry, or wiping the store, records it as done first, so a deletion sticks even when the import did not finish. Done entries are never written again. State is re-read before every save so a concurrent writer of the state file (another host on the same store) loses as little as possible.

func (*Store) List added in v0.107.0

func (s *Store) List(args ListArgs) (ListResponse, error)

func (*Store) ListOrganizeRuns added in v0.107.0

func (s *Store) ListOrganizeRuns() (map[string]any, error)

func (*Store) OrganizerEpoch added in v0.107.0

func (s *Store) OrganizerEpoch() (uint64, error)

OrganizerEpoch returns the current reset generation. A run from an older generation cannot be recreated after history or memory has been cleared.

func (*Store) Overview added in v0.107.0

func (s *Store) Overview(workdir string) (OverviewResponse, error)

func (*Store) PathsInfo added in v0.107.0

func (s *Store) PathsInfo() (map[string]any, error)

func (*Store) QuotaSummary added in v0.107.0

func (s *Store) QuotaSummary(workdir string) (QuotaSummaryResponse, error)

func (*Store) Read added in v0.107.0

func (s *Store) Read(args ReadArgs) (ReadResponse, error)

func (*Store) ReadOrganizeRun added in v0.107.0

func (s *Store) ReadOrganizeRun(id string) (OrganizeRun, error)

func (*Store) RecentRejections added in v0.107.0

func (s *Store) RecentRejections() (map[string]any, error)

func (*Store) Root added in v0.107.0

func (s *Store) Root() string

func (*Store) SaveOrganizeRun added in v0.107.0

func (s *Store) SaveOrganizeRun(run OrganizeRun) (OrganizeRun, error)

SaveOrganizeRun upserts by persisted identity and preserves optional report fields. Runs carrying an executor identity are compare-and-set updates: a late executor cannot overwrite a reset, cancellation, terminal state, or a newer executor's claim.

func (*Store) Search added in v0.107.0

func (s *Store) Search(args SearchArgs) (SearchResponse, error)

func (*Store) TakeUnjudged added in v0.107.6

func (s *Store) TakeUnjudged(session string) ([]UnjudgedMessage, error)

TakeUnjudged returns and clears a session's unjudged list.

func (*Store) TodayDaily added in v0.107.0

func (s *Store) TodayDaily() (any, error)

func (*Store) TodayLocalDate added in v0.107.0

func (s *Store) TodayLocalDate() string

func (*Store) Update added in v0.107.0

func (s *Store) Update(args UpdateArgs) (MutationResponse, error)

func (*Store) UpdateOrganizeRun added in v0.107.0

func (s *Store) UpdateOrganizeRun(run OrganizeRun) (OrganizeRun, error)

func (*Store) WipeAll added in v0.107.0

func (s *Store) WipeAll() (map[string]any, error)

func (*Store) WipeEpoch added in v0.107.6

func (s *Store) WipeEpoch() uint64

WipeEpoch returns how many times memory was wiped. It reads the in-process counter, so it cannot fail; a wipe by another process sharing the root is not seen.

func (*Store) Write added in v0.107.0

func (s *Store) Write(args WriteArgs) (MutationResponse, error)

type StoreError added in v0.107.0

type StoreError struct {
	Code    string
	Message string
}

func (*StoreError) Error added in v0.107.0

func (e *StoreError) Error() string

type UnjudgedMessage added in v0.107.6

type UnjudgedMessage struct {
	ID   string `json:"id"`
	Text string `json:"text"`
}

UnjudgedMessage is a user message the hidden extractor has not judged yet: its turn was stopped or failed, or its extraction did not finish.

type UpdateArgs added in v0.107.0

type UpdateArgs struct {
	ReadArgs
	MemoryType     *string   `json:"memoryType,omitempty"`
	Description    *string   `json:"description,omitempty"`
	Body           *string   `json:"body,omitempty"`
	Mode           string    `json:"mode,omitempty"`
	Actor          string    `json:"actor,omitempty"`
	ConversationID string    `json:"conversationId,omitempty"`
	Model          string    `json:"model,omitempty"`
	Evidence       *Evidence `json:"evidence,omitempty"`
	// Unreviewed is set by internal callers only (hidden extraction).
	Unreviewed *bool `json:"-"`
}

type WriteArgs added in v0.107.0

type WriteArgs struct {
	Slug           string    `json:"slug"`
	Scope          string    `json:"scope"`
	Workdir        string    `json:"workdir,omitempty"`
	MemoryType     string    `json:"memoryType"`
	Description    string    `json:"description"`
	Body           string    `json:"body"`
	Actor          string    `json:"actor,omitempty"`
	ConversationID string    `json:"conversationId,omitempty"`
	Model          string    `json:"model,omitempty"`
	Evidence       *Evidence `json:"evidence,omitempty"`
	Unreviewed     *bool     `json:"unreviewed,omitempty"`
}

Jump to

Keyboard shortcuts

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