cortex

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(name, dir string) error

Create initialises a new Cortex on disk and registers it. dir is the parent directory; the cortex is created as dir/<name>/.

Types

type Cortex

type Cortex struct {
	Name string
	Dir  string
	DB   *db.DB
}

func Open

func Open(name, dir string) (*Cortex, error)

Open opens an existing Cortex by directory path. It ensures required subdirectories exist and auto-purges expired trash.

func (*Cortex) Add

func (c *Cortex) Add(t *trace.Trace) error

Add writes a new Trace to disk and inserts it into the DB.

func (*Cortex) Archive

func (c *Cortex) Archive(id string) error

func (*Cortex) ArchiveDir

func (c *Cortex) ArchiveDir() string

func (*Cortex) Close

func (c *Cortex) Close() error

func (*Cortex) Get

func (c *Cortex) Get(id string) (*Row, error)

func (*Cortex) List

func (c *Cortex) List(opts ListOptions) ([]Row, error)

func (*Cortex) Purge added in v0.2.0

func (c *Cortex) Purge(days int) error

Purge permanently deletes traces that have been in the trash for more than days days. A days value of 0 is treated as 30.

func (*Cortex) Recover added in v0.2.0

func (c *Cortex) Recover(id string) error

Recover moves a trace out of the trash and back to the active traces directory.

func (*Cortex) Remove

func (c *Cortex) Remove(id string) error

Remove permanently deletes a trace from disk and the database. Use Trash for recoverable deletion.

func (*Cortex) Search

func (c *Cortex) Search(query string, opts ListOptions) ([]Row, error)

func (*Cortex) Sync added in v0.2.2

func (c *Cortex) Sync() (SyncResult, error)

Sync reconciles the database with the current state of the markdown files on disk. It walks traces/, archive/traces/, and trash/traces/, upserts every file it finds, and reports orphaned DB rows (not deleted — just reported).

func (*Cortex) TraceFile

func (c *Cortex) TraceFile(id string, archived bool) string

TraceFile returns the absolute path to a trace's markdown file.

func (*Cortex) TracesDir

func (c *Cortex) TracesDir() string

func (*Cortex) Trash added in v0.2.0

func (c *Cortex) Trash(id string) error

Trash moves a trace to the trash directory for deferred deletion.

func (*Cortex) TrashDir added in v0.2.0

func (c *Cortex) TrashDir() string

func (*Cortex) TrashFile added in v0.2.0

func (c *Cortex) TrashFile(id string) string

TrashFile returns the path for a trace in the trash.

func (*Cortex) Unarchive

func (c *Cortex) Unarchive(id string) error

func (*Cortex) Update

func (c *Cortex) Update(id string) error

Update rewrites an existing trace's DB row and FTS entry from its (potentially edited) markdown file on disk.

type ListOptions

type ListOptions struct {
	Type     string
	Author   string
	Tag      string
	Archived bool // only archived (excludes trashed)
	Trashed  bool // only trashed
	All      bool // active + archived (excludes trashed)
}

type Manifest

type Manifest struct {
	Name    string `yaml:"name"`
	Purpose string `yaml:"purpose,omitempty"`
	Owner   string `yaml:"owner,omitempty"`
	Created string `yaml:"created"`
	Version int    `yaml:"version"`
}

Manifest is the cortex.md file at the root of each Cortex.

func ReadManifest added in v0.2.2

func ReadManifest(dir string) (Manifest, error)

ReadManifest parses the cortex.md manifest in the given cortex directory.

type Row

type Row struct {
	ID         string
	Title      string
	Type       string
	Author     string
	Tags       []string
	ArchivedAt string
	TrashedAt  string
	CreatedAt  string
	UpdatedAt  string
}

Row is a DB row joined with tags, returned by list/search operations.

type SyncResult added in v0.2.2

type SyncResult struct {
	Added    int // files found on disk but not in DB
	Updated  int // files found on disk and already in DB (re-synced)
	Orphaned int // IDs in DB with no corresponding file on disk
}

SyncResult summarises what Sync found.

Jump to

Keyboard shortcuts

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