proposal

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package proposal persists write proposals on disk. Agents create them; humans apply them via `sudo cosql apply <id>`.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultDir

func DefaultDir() (string, error)

DefaultDir returns ~/.local/share/cosql/proposals (or $XDG_DATA_HOME).

Types

type DryRun

type DryRun struct {
	Explain     string `json:"explain,omitempty"`
	AffectedEst int64  `json:"affected_est,omitempty"`
}

type Proposal

type Proposal struct {
	ID        string  `json:"id"`
	DB        string  `json:"db"`
	Driver    string  `json:"driver"`
	SQL       string  `json:"sql"`
	Note      string  `json:"note,omitempty"`
	CreatedAt string  `json:"created_at"`
	CreatedBy string  `json:"created_by"`
	DryRun    *DryRun `json:"dry_run,omitempty"`
	Status    Status  `json:"status"`
	AppliedAt string  `json:"applied_at,omitempty"`
	AppliedBy string  `json:"applied_by,omitempty"`
	Result    *Result `json:"result,omitempty"`
}

Proposal is what gets written to disk as <id>.json.

type Result

type Result struct {
	AffectedRows int64  `json:"affected_rows"`
	DurationMS   int64  `json:"duration_ms"`
	Error        string `json:"error,omitempty"`
}

type Status

type Status string

Status is the proposal lifecycle state.

const (
	StatusPending  Status = "pending"
	StatusApplied  Status = "applied"
	StatusRejected Status = "rejected"
	StatusExpired  Status = "expired"

	// DefaultTTL is the age after which a pending proposal is considered expired.
	DefaultTTL = 7 * 24 * time.Hour
)

type Store

type Store struct{ Dir string }

Store is the filesystem-backed proposal store.

func Open

func Open() (*Store, error)

Open returns a Store rooted at DefaultDir, creating the directory on demand.

func (*Store) Get

func (s *Store) Get(id string) (*Proposal, error)

Get returns the proposal with the given id (exact match).

func (*Store) List

func (s *Store) List(filter Status) ([]*Proposal, error)

List returns all proposals, optionally filtered by status.

func (*Store) New

func (s *Store) New(p Proposal) (string, error)

New creates a new pending proposal and writes it to disk. Returns the id.

func (*Store) Update

func (s *Store) Update(p *Proposal) error

Update writes the given proposal back to disk.

Jump to

Keyboard shortcuts

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