work

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package work implements the local-first domain store for the work CLI.

Index

Constants

View Source
const (
	// CurrentRecordSchemaVersion is the durable YAML schema version for inbox
	// and work item records.
	CurrentRecordSchemaVersion = 1
)
View Source
const (
	// DefaultStoreDir is the repository-relative store path used by the CLI.
	DefaultStoreDir = ".work"
)

Variables

View Source
var (
	ErrNotInitialized  = errors.New("work store is not initialized")
	ErrNotFound        = errors.New("work item not found")
	ErrAlreadyExists   = errors.New("work store file already exists")
	ErrAlreadyAccepted = errors.New("inbox item already accepted")
	ErrAlreadyClaimed  = errors.New("work item already claimed")
	ErrStoreLocked     = errors.New("work store is locked")
)

Functions

This section is empty.

Types

type AcceptInboxOptions

type AcceptInboxOptions struct {
	Title       string
	Type        string
	Description string
	Status      WorkStatus
	Priority    string
	Area        string
	Labels      []string
	Metadata    map[string]string
}

AcceptInboxOptions controls how an inbox item becomes a work item.

type Actor added in v0.2.0

type Actor struct {
	ID      string    `yaml:"id" json:"id"`
	Kind    ActorKind `yaml:"kind" json:"kind"`
	Label   string    `yaml:"label,omitempty" json:"label,omitempty"`
	Runtime string    `yaml:"runtime,omitempty" json:"runtime,omitempty"`
	Model   string    `yaml:"model,omitempty" json:"model,omitempty"`
}

Actor identifies the human, agent runtime, script, or automation touching coordination records such as leases and attempts.

type ActorKind added in v0.2.0

type ActorKind string
const (
	ActorKindHuman      ActorKind = "human"
	ActorKindAgent      ActorKind = "agent"
	ActorKindAutomation ActorKind = "automation"
)

type ClaimWorkItemInput added in v0.2.0

type ClaimWorkItemInput struct {
	ID      string
	Actor   Actor
	Session *Session
	TTL     time.Duration
}

ClaimWorkItemInput describes a lease claim request.

type InboxItem

type InboxItem struct {
	SchemaVersion int               `yaml:"schema_version" json:"schema_version"`
	ID            string            `yaml:"id" json:"id"`
	Title         string            `yaml:"title" json:"title"`
	Body          string            `yaml:"body,omitempty" json:"body,omitempty"`
	Source        string            `yaml:"source,omitempty" json:"source,omitempty"`
	Status        InboxStatus       `yaml:"status" json:"status"`
	Labels        []string          `yaml:"labels,omitempty" json:"labels,omitempty"`
	Metadata      map[string]string `yaml:"metadata,omitempty" json:"metadata,omitempty"`
	AcceptedAs    string            `yaml:"accepted_as,omitempty" json:"accepted_as,omitempty"`
	CreatedAt     time.Time         `yaml:"created_at" json:"created_at"`
	UpdatedAt     time.Time         `yaml:"updated_at" json:"updated_at"`
	AcceptedAt    *time.Time        `yaml:"accepted_at,omitempty" json:"accepted_at,omitempty"`
}

InboxItem is a captured piece of untriaged work.

type InboxItemInput

type InboxItemInput struct {
	Title    string
	Body     string
	Source   string
	Labels   []string
	Metadata map[string]string
}

InboxItemInput describes an inbox item to create.

type InboxStatus

type InboxStatus string
const (
	InboxStatusOpen     InboxStatus = "open"
	InboxStatusAccepted InboxStatus = "accepted"
)

type MigrateInput added in v0.2.1

type MigrateInput struct {
	DryRun bool
}

MigrateInput controls safe, idempotent store migrations.

type MigrationRecordResult added in v0.2.1

type MigrationRecordResult struct {
	Scanned int `json:"scanned"`
	Changed int `json:"changed"`
}

MigrationRecordResult summarizes one migrated record class.

type MigrationResult added in v0.2.1

type MigrationResult struct {
	DryRun     bool                  `json:"dry_run"`
	InboxItems MigrationRecordResult `json:"inbox_items"`
	WorkItems  MigrationRecordResult `json:"work_items"`
}

MigrationResult summarizes the store records scanned and changed.

func (MigrationResult) Changed added in v0.2.1

func (r MigrationResult) Changed() int

Changed returns the total records changed, or that would change in dry-run.

type Session added in v0.2.0

type Session struct {
	ID       string `yaml:"id,omitempty" json:"id,omitempty"`
	ThreadID string `yaml:"thread_id,omitempty" json:"thread_id,omitempty"`
	TurnID   string `yaml:"turn_id,omitempty" json:"turn_id,omitempty"`
}

Session records optional runtime provenance for an external agent session.

type Store

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

func New

func New(storePath string) *Store

New returns a Store rooted at storePath. An empty storePath uses .work.

func (*Store) AcceptInboxItem

func (s *Store) AcceptInboxItem(id string, opts AcceptInboxOptions) (WorkItem, error)

AcceptInboxItem turns an inbox item into a work item and marks the inbox item accepted.

func (*Store) AddInboxItem

func (s *Store) AddInboxItem(input InboxItemInput) (InboxItem, error)

AddInboxItem captures an untriaged item in .work/inbox.

func (*Store) ClaimWorkItem added in v0.2.0

func (s *Store) ClaimWorkItem(input ClaimWorkItemInput) (WorkLease, error)

ClaimWorkItem writes or renews a time-bounded lease for a work item.

func (*Store) CreateWorkItem

func (s *Store) CreateWorkItem(input WorkItemInput) (WorkItem, error)

CreateWorkItem creates a work item directly, bypassing the inbox.

func (*Store) GetInboxItem

func (s *Store) GetInboxItem(id string) (InboxItem, error)

GetInboxItem returns one inbox item by ID.

func (*Store) GetWorkItem

func (s *Store) GetWorkItem(id string) (WorkItem, error)

GetWorkItem returns a work item by ID.

func (*Store) GetWorkLease added in v0.2.0

func (s *Store) GetWorkLease(id string) (WorkLease, bool, error)

GetWorkLease returns the active lease for a work item, if one exists.

func (*Store) GetWorkPolicy added in v0.2.0

func (s *Store) GetWorkPolicy(id string) (WorkPolicy, bool, error)

GetWorkPolicy returns the type-level policy for a typed work item, if one exists.

func (*Store) Init

func (s *Store) Init() error

Init creates the local work store layout. Existing files are left intact, making Init safe to run repeatedly.

func (*Store) ListInbox

func (s *Store) ListInbox() ([]InboxItem, error)

ListInbox returns open inbox items sorted by ID.

func (*Store) ListView

func (s *Store) ListView(idOrName string) (ViewResult, error)

ListView materializes the saved view identified by ID or case-insensitive name.

func (*Store) ListWorkItems

func (s *Store) ListWorkItems(filter WorkItemFilter) ([]WorkItem, error)

ListWorkItems returns work items matching filter, sorted by ID.

func (*Store) Migrate added in v0.2.1

func (s *Store) Migrate(input MigrateInput) (MigrationResult, error)

Migrate applies safe, idempotent migrations for older work stores.

func (*Store) Root

func (s *Store) Root() string

Root returns the filesystem path backing the store.

type View

type View struct {
	ID          string         `yaml:"id" json:"id"`
	Name        string         `yaml:"name" json:"name"`
	Description string         `yaml:"description,omitempty" json:"description,omitempty"`
	Filter      WorkItemFilter `yaml:"filter,omitempty" json:"filter,omitempty"`
}

View is a named saved filter over work items.

type ViewResult

type ViewResult struct {
	View  View       `json:"view"`
	Items []WorkItem `json:"items"`
}

ViewResult is the materialized item list for a saved view.

type WorkItem

type WorkItem struct {
	SchemaVersion int               `yaml:"schema_version" json:"schema_version"`
	ID            string            `yaml:"id" json:"id"`
	Title         string            `yaml:"title" json:"title"`
	Type          string            `yaml:"type,omitempty" json:"type,omitempty"`
	Description   string            `yaml:"description,omitempty" json:"description,omitempty"`
	Status        WorkStatus        `yaml:"status" json:"status"`
	Priority      string            `yaml:"priority,omitempty" json:"priority,omitempty"`
	Area          string            `yaml:"area,omitempty" json:"area,omitempty"`
	Labels        []string          `yaml:"labels,omitempty" json:"labels,omitempty"`
	SourceInboxID string            `yaml:"source_inbox_id,omitempty" json:"source_inbox_id,omitempty"`
	Metadata      map[string]string `yaml:"metadata,omitempty" json:"metadata,omitempty"`
	CreatedAt     time.Time         `yaml:"created_at" json:"created_at"`
	UpdatedAt     time.Time         `yaml:"updated_at" json:"updated_at"`
}

WorkItem is the durable unit tracked by the work CLI.

type WorkItemFilter

type WorkItemFilter struct {
	IDs      []string     `yaml:"ids,omitempty" json:"ids,omitempty"`
	Statuses []WorkStatus `yaml:"statuses,omitempty" json:"statuses,omitempty"`
	Areas    []string     `yaml:"areas,omitempty" json:"areas,omitempty"`
	Labels   []string     `yaml:"labels,omitempty" json:"labels,omitempty"`
	Text     string       `yaml:"text,omitempty" json:"text,omitempty"`
}

WorkItemFilter is used by ListWorkItems and View definitions.

type WorkItemInput

type WorkItemInput struct {
	Title         string
	Type          string
	Description   string
	Status        WorkStatus
	Priority      string
	Area          string
	Labels        []string
	SourceInboxID string
	Metadata      map[string]string
}

WorkItemInput describes a work item to create.

type WorkLease added in v0.2.0

type WorkLease struct {
	WorkItemID string    `yaml:"work_item_id" json:"work_item_id"`
	Actor      Actor     `yaml:"actor" json:"actor"`
	Session    *Session  `yaml:"session,omitempty" json:"session,omitempty"`
	AcquiredAt time.Time `yaml:"acquired_at" json:"acquired_at"`
	ExpiresAt  time.Time `yaml:"expires_at" json:"expires_at"`
}

WorkLease is a time-bounded claim on a work item.

type WorkPolicy added in v0.2.0

type WorkPolicy struct {
	WorkItemID string `yaml:"work_item_id" json:"work_item_id"`
	WorkType   string `yaml:"work_type" json:"work_type"`
	Path       string `yaml:"path" json:"path"`
	Body       string `yaml:"body" json:"body"`
}

WorkPolicy is the agent-facing policy attached to a work type.

type WorkStatus

type WorkStatus string
const (
	WorkStatusReady     WorkStatus = "ready"
	WorkStatusActive    WorkStatus = "active"
	WorkStatusBlocked   WorkStatus = "blocked"
	WorkStatusDone      WorkStatus = "done"
	WorkStatusCancelled WorkStatus = "cancelled"
)

Jump to

Keyboard shortcuts

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