dossiers

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 22 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 dossiers keeps the lifecycle of the unit and project dossiers.

Index

Constants

View Source
const KindCall = "dossier_call"

KindCall is the loop event of one dossier call; its Data is the cost in USD.

View Source
const KindRestored = "dossier_restored"

KindRestored is the loop event of a file a turn wrote against the write rules; Data names the file.

View Source
const LogDir = "log"

LogDir holds the append-only log of a dossier.

View Source
const LogTime = "20060102T150405Z"

LogTime is the UTC time that starts a log file's name.

View Source
const MaxNotes = 32 * dossier.KB

MaxNotes is the largest notes.md body a call may write.

View Source
const Notes = "notes.md"

Notes is the curated file of a dossier: only a compaction or a closing call rewrites it.

Variables

View Source
var ErrOverCap = errors.New("the headless spend cap is reached")

ErrOverCap is a call the day's headless spend leaves no room for; it is retried on a later day.

View Source
var WriteDirs = []string{LogDir, "sources", "drafts"}

WriteDirs are the subdirectories of its dossier a session may write in.

Functions

This section is empty.

Types

type Archiver

type Archiver interface {
	Archive(ctx context.Context, dir, tarball string) error
	Restore(ctx context.Context, tarball, dir string) error
	Remove(ctx context.Context, path string) error
}

Archiver is the lifecycle side of Files.

type Calls

type Calls struct {
	Turns *Turns
	Asker turns.Asker
	Caps  Caps
	// Spent is the day's headless spend as stored, the dossier calls Record wrote included; nil counts none.
	Spent func(ctx context.Context, day time.Time) (float64, error)
	// Record stores a call's cost, the reported one or else the per-call cap, so Spent counts it; nil stores none.
	Record func(ctx context.Context, u unit.Unit, cost float64) error
	// contains filtered or unexported fields
}

Calls runs the dossiers' compaction and closing calls under the headless caps.

func (*Calls) Compact

func (c *Calls) Compact(ctx context.Context, u unit.Unit) (bool, error)

Compact rewrites u's notes.md from its notes and the log files written since the last compaction, once those pass the policy's CompactAt; the log files stay. It reports whether it rewrote notes.md.

func (*Calls) Reserved

func (c *Calls) Reserved() float64

Reserved is the per-call caps of the calls running, which no store holds yet.

type Caps

type Caps struct {
	PerCallUSD, PerDayUSD float64
	// Tier is the model tier of the calls; "" is balanced.
	Tier turns.Tier
}

type Change

type Change struct {
	Rel  string
	Kind string // added, modified, deleted
}

type Entry

type Entry struct {
	Rel   string
	Kind  EntryKind
	Size  int64
	Links uint64 // hard links to a file's inode; 0 unknown
}

Entry is a dossier path as it lies on disk, symlinks unfollowed.

type EntryKind

type EntryKind string
const (
	Missing EntryKind = ""
	File    EntryKind = "file"
	Folder  EntryKind = "dir"
	Symlink EntryKind = "symlink"
	Other   EntryKind = "other"
)

type Files

type Files interface {
	Tree
	Archiver
}

Files is implemented by internal/adapter/dossier.

type PageReader

type PageReader interface {
	Stat(ctx context.Context, dir, rel string) (Entry, error)
	// List is the regular files under rel, at any depth, sorted by Rel.
	List(ctx context.Context, dir, rel string) ([]Entry, error)
	Read(ctx context.Context, dir, rel string) ([]byte, error)
	// Committed is rel's content in the last commit; ok false when it holds no such file.
	Committed(ctx context.Context, dir, rel string) (data []byte, ok bool, err error)
}

type PageWriter

type PageWriter interface {
	// Write creates or replaces rel as a regular file of mode 0600.
	Write(ctx context.Context, dir, rel string, data []byte) error
	// Discard removes rel and whatever it holds, never following a symlink.
	Discard(ctx context.Context, dir, rel string) error
}

type Pages

type Pages interface {
	PageReader
	PageWriter
}

Pages reads and writes single files of a dossier; implemented by internal/adapter/dossier, which refuses any path that leaves the dossier.

type Report

type Report struct {
	Dossiers, Archives, Transcripts Usage
	OverCap                         []dossier.Owner
}

func (Report) OverTotal

func (r Report) OverTotal(p dossier.Policy) bool

OverTotal reports whether the dossiers and their archives pass the policy's total cap.

type Resolution

type Resolution struct {
	Calls *Calls
	// Items are the unit's items the closing call reads; nil reads none.
	Items func(ctx context.Context, u unit.Unit) ([]items.Item, error)
	Log   func(format string, args ...any)
	// contains filtered or unexported fields
}

Resolution follows the units' open work into their dossiers: a unit with an active dossier, items, and no open item or entry gets its closing call and is resolved; a resolved or archived one with open work again is reopened. A call the daily cap refuses waits for a later Retry.

func (*Resolution) All

func (r *Resolution) All(ctx context.Context) error

All follows every unit dossier.

func (*Resolution) Compact

func (r *Resolution) Compact(ctx context.Context, u unit.Unit) error

Compact runs u's compaction when its log passed the threshold; a refusal of the cap defers it.

func (*Resolution) Retry

func (r *Resolution) Retry(ctx context.Context) error

Retry runs the closing calls and compactions the cap deferred.

func (*Resolution) Units

func (r *Resolution) Units(ctx context.Context, us ...unit.Unit) error

Units follows each of us whose dossier exists.

func (*Resolution) Watch

func (r *Resolution) Watch(ctx context.Context, changes port.Changes, retry time.Duration)

Watch follows the units of each TopicItems or TopicEntries note, everything once at start, and runs Retry every retry, until ctx ends; the subscriber only queues.

type Service

type Service struct {
	Store    Store
	Files    Files
	Policy   dossier.Policy
	StateDir string
	Clock    port.Clock
}

func (*Service) Get

func (*Service) Open

func (s *Service) Open(ctx context.Context, o dossier.Owner) (dossier.Dossier, error)

Open creates or revives o's dossier.

func (*Service) Reopened

func (s *Service) Reopened(ctx context.Context, o dossier.Owner) error

Reopened makes o's dossier active again, restoring its archive; it creates none.

func (*Service) Report

func (s *Service) Report(ctx context.Context) (Report, error)

Report sums the dossiers on disk and their archives, and names each dossier over the soft cap. Transcripts are the caller's: the service does not know them.

func (*Service) Resolved

func (s *Service) Resolved(ctx context.Context, o dossier.Owner, at time.Time) error

Resolved starts the archive countdown of o's active dossier; it does nothing to an absent one.

func (*Service) Sweep

func (s *Service) Sweep(ctx context.Context) (archived, purged int, err error)

Sweep is the lifecycle job: it refreshes each dossier's usage, archives a dossier ArchiveAfter its owner resolved and purges an archive PurgeAfter it was made. Before either, it asks the store whether the owner is open again, and revives the dossier when it is.

type Store

type Store interface {
	// Put inserts or replaces d's row; Path is not stored.
	Put(ctx context.Context, d dossier.Dossier) error
	// Get is o's row, with Path empty.
	Get(ctx context.Context, o dossier.Owner) (dossier.Dossier, bool, error)
	List(ctx context.Context) ([]dossier.Dossier, error)
	// Open reports whether o has an open item or a live entry; a project, whether its entry is open.
	Open(ctx context.Context, o dossier.Owner) (bool, error)
}

Store keeps the dossiers table and answers whether an owner still has open work.

type Tree

type Tree interface {
	// Ensure creates the dossier's layout and repository at dir, or completes them; it refuses a
	// dir outside the dossiers root and a state directory inside a repository checkout.
	Ensure(ctx context.Context, dir string) error
	// Usage is the bytes on disk under dir, its repository included, and the count of its files
	// outside the repository; an absent dir is empty.
	Usage(ctx context.Context, dir string) (bytes int64, files int, err error)
	// Commit commits paths with message, every change when no path is named; a path written after the
	// caller judged it stays out unless it is named.
	Commit(ctx context.Context, dir, message string, paths ...string) error
	Changed(ctx context.Context, dir string) ([]Change, error) // against the last commit
	RestoreFile(ctx context.Context, dir, rel string) error    // from the last commit
}

Tree is the working side of Files: a dossier's directory and its history.

type Turns

type Turns struct {
	Dossiers *Service
	Pages    Pages
	// Events records loop events on the dossier's unit; nil records none.
	Events func(ctx context.Context, ev port.Event) error
	Log    func(format string, args ...any)

	// Serial, when set, is the lock every Turns of one state directory shares; nil uses the Turns' own.
	Serial *sync.Mutex
	// contains filtered or unexported fields
}

Turns opens a unit's dossier for its turns and holds the write rules after each one: what broke a rule is restored from the last commit, the rest is committed.

func (*Turns) Check

func (t *Turns) Check(ctx context.Context, u unit.Unit, message string) ([]Violation, error)

Check holds u's dossier to the write rules after a turn and commits it with message; a dossier that is absent or neither active nor resolved is left alone.

func (*Turns) HeadlessLog

func (t *Turns) HeadlessLog(ctx context.Context, u unit.Unit, seq int64, text string) error

HeadlessLog writes a headless turn's log entry as log/<ts>-headless-<seq>.md and commits it as the turn.

func (*Turns) Open

func (t *Turns) Open(ctx context.Context, u unit.Unit) (dossier.Dossier, error)

Open opens u's dossier for a turn, first settling what was written since its last commit.

func (*Turns) Opened

func (t *Turns) Opened(ctx context.Context, d dossier.Dossier) (time.Time, error)

Opened is when d was first opened: its notes' opened time, else their first updated time.

type Usage

type Usage struct {
	Bytes int64
	Count int
}

type Violation

type Violation struct{ Rel, Why string }

Violation is a file a turn wrote against the write rules, and the rule.

Jump to

Keyboard shortcuts

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