Documentation
¶
Overview ¶
Package dossiers keeps the lifecycle of the unit and project dossiers.
Index ¶
- Constants
- Variables
- type Archiver
- type Calls
- type Caps
- type Change
- type Entry
- type EntryKind
- type Files
- type PageReader
- type PageWriter
- type Pages
- type Report
- type Resolution
- func (r *Resolution) All(ctx context.Context) error
- func (r *Resolution) Compact(ctx context.Context, u unit.Unit) error
- func (r *Resolution) Retry(ctx context.Context) error
- func (r *Resolution) Units(ctx context.Context, us ...unit.Unit) error
- func (r *Resolution) Watch(ctx context.Context, changes port.Changes, retry time.Duration)
- type Service
- func (s *Service) Get(ctx context.Context, o dossier.Owner) (dossier.Dossier, bool, error)
- func (s *Service) Open(ctx context.Context, o dossier.Owner) (dossier.Dossier, error)
- func (s *Service) Reopened(ctx context.Context, o dossier.Owner) error
- func (s *Service) Report(ctx context.Context) (Report, error)
- func (s *Service) Resolved(ctx context.Context, o dossier.Owner, at time.Time) error
- func (s *Service) Sweep(ctx context.Context) (archived, purged int, err error)
- type Store
- type Tree
- type Turns
- func (t *Turns) Check(ctx context.Context, u unit.Unit, message string) ([]Violation, error)
- func (t *Turns) HeadlessLog(ctx context.Context, u unit.Unit, seq int64, text string) error
- func (t *Turns) Open(ctx context.Context, u unit.Unit) (dossier.Dossier, error)
- func (t *Turns) Opened(ctx context.Context, d dossier.Dossier) (time.Time, error)
- type Usage
- type Violation
Constants ¶
const KindCall = "dossier_call"
KindCall is the loop event of one dossier call; its Data is the cost in USD.
const KindRestored = "dossier_restored"
KindRestored is the loop event of a file a turn wrote against the write rules; Data names the file.
const LogDir = "log"
LogDir holds the append-only log of a dossier.
const LogTime = "20060102T150405Z"
LogTime is the UTC time that starts a log file's name.
const MaxNotes = 32 * dossier.KB
MaxNotes is the largest notes.md body a call may write.
const Notes = "notes.md"
Notes is the curated file of a dossier: only a compaction or a closing call rewrites it.
Variables ¶
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.
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.
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 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 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 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 ¶
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.
type Service ¶
type Service struct {
Store Store
Files Files
Policy dossier.Policy
StateDir string
Clock port.Clock
}
func (*Service) Reopened ¶
Reopened makes o's dossier active again, restoring its archive; it creates none.
func (*Service) Report ¶
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 ¶
Resolved starts the archive countdown of o's active dossier; it does nothing to an absent one.
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 ¶
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 ¶
HeadlessLog writes a headless turn's log entry as log/<ts>-headless-<seq>.md and commits it as the turn.