Documentation
¶
Overview ¶
Package work is the Work module: the Work engine (README.md) of typed items, links and saved views kept in Caster under the contract work/v1, with three apps as presets over it (Content, Planner, Writer). A workspace's index is in the namespace "work"; its kinds, items and views are in its own namespace, w-<workspace>. Caster and Torque are reached through Tether's tools (module/tetherlink).
Ported from Basalisk (internal/work, internal/api/work.go, frontend/src/work/agent.ts); the data in Caster is the same, so either reads and writes what the other wrote.
Index ¶
- Constants
- Variables
- func ItemName(id string) string
- func KindName(kind string) string
- func NS(workspace string) string
- func NewID() string
- func Presets() map[string]Preset
- func Ref(ns, name string) string
- func RoundName(id string, n int) string
- func ValidID(s string) bool
- func ValidKind(s string) bool
- func ValidSlug(s string) bool
- func ViewName(id string) string
- type Bind
- type Body
- type Caller
- type CanvasNote
- type Card
- type Caster
- type Conflict
- type Detail
- type Doc
- func (d *Doc) Bool(key string) bool
- func (d *Doc) Decode(key string, v any) error
- func (d *Doc) Del(key string)
- func (d *Doc) Has(key string) bool
- func (d *Doc) Num(key string) float64
- func (d *Doc) Set(key string, v any) error
- func (d *Doc) SetField(key string, v any) error
- func (d *Doc) Str(key string) string
- func (d *Doc) String() string
- func (d *Doc) Strings(key string) []string
- type Edit
- type ErrOpenNotes
- type Field
- type GatewayCaster
- func (g GatewayCaster) Get(ctx context.Context, ns, name string, rev int) (Item, bool, error)
- func (g GatewayCaster) List(ctx context.Context, ns string) ([]Head, error)
- func (g GatewayCaster) Log(ctx context.Context, ns, name string) ([]Revision, error)
- func (g GatewayCaster) Put(ctx context.Context, ns, name, content, title string) (int, error)
- type GatewayNotifier
- type Head
- type Item
- type Kind
- type LayoutPatch
- type Link
- type Material
- type NameKind
- type NewItem
- type Note
- type Notifier
- type Pinner
- type Pos
- type Preset
- type Published
- type Revision
- type RoundNote
- type RoundView
- type Section
- type Sent
- type Signed
- type SignedOff
- type Space
- type Stack
- type Store
- func (s *Store) AddNote(ctx context.Context, ws, id string, n Note) (Note, error)
- func (s *Store) ApplyTemplate(ctx context.Context, ws, id string) error
- func (s *Store) At(ctx context.Context, ws, name string, rev int) (Item, bool, error)
- func (s *Store) Cut(ctx context.Context, ws, id string) error
- func (s *Store) Detail(ctx context.Context, ws, id string) (Detail, bool, error)
- func (s *Store) DropNote(ctx context.Context, ws, id string) error
- func (s *Store) EditItem(ctx context.Context, ws, id string, e Edit) (int, error)
- func (s *Store) EditNote(ctx context.Context, ws, id string, text, replace *string) error
- func (s *Store) Kinds(ctx context.Context, ns string) (map[string]Kind, []Kind)
- func (s *Store) Log(ctx context.Context, ws, name string) ([]Revision, error)
- func (s *Store) MakeItem(ctx context.Context, ws string, in NewItem) (string, error)
- func (s *Store) Move(ctx context.Context, ws, id, key, value string) (int, error)
- func (s *Store) NSOf(ctx context.Context, ws string) string
- func (s *Store) NewWorkspace(ctx context.Context, slug, title, preset, about string) (string, error)
- func (s *Store) Notes(ctx context.Context, ws, item string) ([]Note, error)
- func (s *Store) Open(ctx context.Context, ws string) (Space, bool, error)
- func (s *Store) PatchLayout(ctx context.Context, ws, view string, p LayoutPatch) (int, error)
- func (s *Store) Place(ctx context.Context, ws, id, parent, before, view string) error
- func (s *Store) Refresh(ctx context.Context, ns string, force bool) (int, error)
- func (s *Store) Restore(ctx context.Context, ws, id string) error
- func (s *Store) Rounds(ctx context.Context, ws, id string) ([]RoundView, error)
- func (s *Store) SaveView(ctx context.Context, ws, id string, set map[string]any) (int, error)
- func (s *Store) SendRound(ctx context.Context, ws, id string, tell Notifier) (Sent, error)
- func (s *Store) SendToTorque(ctx context.Context, ws, id string) (task string, created bool, err error)
- func (s *Store) SetOwners(ctx context.Context, ws string, owners []string) error
- func (s *Store) SignOff(ctx context.Context, ws, id string, anyway bool, pin Pinner, tell Notifier) (Signed, error)
- func (s *Store) TorqueStatus(ctx context.Context, task string) (TaskStatus, error)
- func (s *Store) Unsign(ctx context.Context, ws, id string) error
- func (s *Store) UpdateWorkspace(ctx context.Context, ws string, title *string, archived, deleted *bool) error
- func (s *Store) Views(ctx context.Context, ns string) []View
- func (s *Store) Workspaces(ctx context.Context, app string) ([]Workspace, error)
- type TaskStatus
- type TemplateInfo
- type View
- type Workspace
Constants ¶
const IndexNS = "work"
IndexNS is the namespace that lists the workspaces.
const RoundFrom = "msg://user/local/operator"
RoundFrom is the address a round's mail goes out from: the owner's, as the feedback is his.
const StagePublished = "published"
StagePublished is the stage that means it went out; reaching it starts the publication log.
Variables ¶
var ErrNoCaster = errors.New("Caster is not reachable: set work.tether_command (or work.tether_url) in Settings")
ErrNoCaster says there is no way to reach Caster configured, so nothing can be written.
var ErrNoTorque = errors.New("torque is not reachable here (no link to Tether)")
ErrNoTorque says Torque cannot be reached (no link to Tether).
var ErrNotFound = errors.New("there is no such workspace or item")
ErrNotFound says there is no such workspace or item.
var NoteKinds = []string{"comment", "suggestion"}
NoteKinds a draft note may be.
var Relations = []string{"contains", "depends-on", "leads-to", "appears-in", "uses", "relates"}
Relations every workspace knows; a kind set may add more.
var ViewKinds = []string{"board", "calendar", "outline", "canvas", "flow"}
ViewKinds are the views a workspace may hold.
Functions ¶
func ItemName ¶
ItemName is an item's name in a workspace's namespace (KindName and ViewName are a kind's and a view's).
Types ¶
type Bind ¶
type Bind struct {
Key string `json:"key" yaml:"key"` // stage | parent
Value string `json:"value" yaml:"value"`
}
Bind is what a stack sets on a card dropped into it.
type Body ¶
Body is an item's body split on its "## " headings. Text before the first heading and sections with headings the kind does not name are kept as they are.
type Caller ¶
type Caller interface {
Call(ctx context.Context, tool string, args map[string]any) ([]byte, error)
}
Caller is what the gateway link offers (link.go, over module/tetherlink). CallAll, when it has it, reads the whole of a result the gateway cut.
type CanvasNote ¶
type CanvasNote struct {
ID string `json:"id" yaml:"id"`
X float64 `json:"x" yaml:"x"`
Y float64 `json:"y" yaml:"y"`
Text string `json:"text" yaml:"text"`
}
CanvasNote is a free note on the canvas.
type Card ¶
type Card struct {
ID string `json:"id"`
Kind string `json:"kind"`
Title string `json:"title"`
Stage string `json:"stage"`
Fields map[string]any `json:"fields"`
Parent string `json:"parent,omitempty"`
Children []string `json:"children"`
Links []Link `json:"links"`
Material []Material `json:"material"`
Published []Published `json:"published"`
Task string `json:"task,omitempty"`
Tags []string `json:"tags"`
Cut bool `json:"cut,omitempty"`
Signed bool `json:"signed,omitempty"` // signed off
StaleSign bool `json:"stale_sign,omitempty"` // signed off, and its text changed since
Excerpt string `json:"excerpt,omitempty"`
Words int `json:"words"`
Rev int `json:"rev"`
Updated string `json:"updated"`
Problem string `json:"problem,omitempty"`
}
Card is an item as the views show it.
type Caster ¶
type Caster interface {
// List is every item in a namespace, latest revision each.
List(ctx context.Context, ns string) ([]Head, error)
// Get is an item's text at a revision (0 = latest). ok is false when there is no such item.
Get(ctx context.Context, ns, name string, rev int) (it Item, ok bool, err error)
// Put makes a new revision of ns/name (none when the content is the same) and returns it.
Put(ctx context.Context, ns, name, content, title string) (rev int, err error)
// Log is an item's revisions, newest first.
Log(ctx context.Context, ns, name string) ([]Revision, error)
}
Caster is where the work items live: the index in namespace "work", each workspace in its own. The store keeps a working copy and writes through this; tests give it a stand-in.
type Conflict ¶
Conflict says the item moved on in Caster after the owner began the edit. Nothing was overwritten; the owner's changed sections were kept as suggestions on the newer revision (and any other change as a comment).
type Detail ¶
type Detail struct {
Card
Ref string `json:"ref"`
Sections map[string]string `json:"sections"`
Order []string `json:"order"` // the sections shown: the kind's, then any other heading
Lead string `json:"lead,omitempty"`
Notes []Note `json:"notes"`
Rounds []RoundView `json:"rounds"` // sent, newest first
SignOff *SignedOff `json:"sign_off,omitempty"` // the item's sign-off, if any
Changed bool `json:"changed_since_round"` // revised since the last round was sent
Owners []string `json:"owners"` // the workspace's: who rounds are mailed to
}
Detail is one item opened: its card, its sections and the owner's notes on it.
type Doc ¶
Doc is an item's text: YAML front matter and a markdown body, or (Plain) a YAML document with no body, as kinds and views are. Keys the app does not know are kept as they are when it writes the item again.
func ParsePlain ¶
ParsePlain reads a YAML document (a kind, a view). A leading "---" line is allowed.
func (*Doc) Decode ¶
Decode reads a key into v (for the structured keys: fields, links, material, published).
func (*Doc) SetField ¶
SetField sets one key of the "fields" mapping, keeping the others as they are (nil takes it out).
type Edit ¶
type Edit struct {
BaseRev int `json:"base_rev"`
Title *string `json:"title"`
Fields map[string]any `json:"fields"`
Sections map[string]string `json:"sections"`
Tags *[]string `json:"tags"`
// Stage, Material and Published replace the item's value when given.
Stage *string `json:"stage"`
Material *[]Material `json:"material"`
Published *[]Published `json:"published"`
// Links replaces the item's typed links (never "contains": that is parent and children).
Links *[]Link `json:"links"`
}
Edit is the owner's change to an item, made on the revision BaseRev. Nil fields are left alone; Fields sets the keys given (null takes one out).
type ErrOpenNotes ¶
ErrOpenNotes refuses a sign-off while the last round has notes the team has not answered, or cannot be read (then nothing says its notes were answered).
func (*ErrOpenNotes) Error ¶
func (e *ErrOpenNotes) Error() string
type Field ¶
type Field struct {
Key string `yaml:"key" json:"key"`
Label string `yaml:"label,omitempty" json:"label,omitempty"`
Type string `yaml:"type" json:"type"` // text | number | date | enum | ref | refs | url | bool
Options []string `yaml:"options,omitempty" json:"options,omitempty"`
}
Field is one typed field of a kind.
type GatewayCaster ¶
type GatewayCaster struct{ Link Caller }
GatewayCaster reaches Caster through the Tether gateway.
type GatewayNotifier ¶
type GatewayNotifier struct{ Link Caller }
GatewayNotifier tells the team through the Tether gateway.
func (GatewayNotifier) Comment ¶
func (g GatewayNotifier) Comment(ctx context.Context, task, text string) error
type Kind ¶
type Kind struct {
Kind string `yaml:"kind" json:"kind"`
Label string `yaml:"label" json:"label"`
Plural string `yaml:"plural,omitempty" json:"plural,omitempty"`
Icon string `yaml:"icon,omitempty" json:"icon,omitempty"` // a lucide name
Stages []string `yaml:"stages" json:"stages"`
Fields []Field `yaml:"fields" json:"fields"`
Sections []string `yaml:"sections" json:"sections"`
Children []string `yaml:"children" json:"children"`
Color string `yaml:"color,omitempty" json:"color,omitempty"`
Rev int `yaml:"-" json:"rev"`
Problem string `yaml:"-" json:"problem,omitempty"`
}
Kind is what an item is: data, not code. Shipped in presets and copied into a workspace, where it can be edited.
type LayoutPatch ¶
type LayoutPatch struct {
Cards map[string]*Pos `json:"cards"`
Stacks map[string]*Stack `json:"stacks"`
Notes map[string]*CanvasNote `json:"notes"`
}
LayoutPatch changes a layout by id: a card's place, a stack or a note set (null takes it out). Stacks and notes keep their order; a new one goes at the end.
type Material ¶
type Material struct {
Ref string `yaml:"ref" json:"ref"`
Caption string `yaml:"caption,omitempty" json:"caption,omitempty"`
}
Material is a reference to something kept elsewhere, never a copy.
type NewItem ¶
type NewItem struct {
Kind string `json:"kind"`
Title string `json:"title"`
Stage string `json:"stage"`
Parent string `json:"parent"`
Fields map[string]any `json:"fields"`
Tags []string `json:"tags"`
Links []Link `json:"links"`
Sections map[string]string `json:"sections"`
}
NewItem is what the owner asks to make.
type Note ¶
type Note struct {
ID string `json:"id"`
WS string `json:"ws"`
Item string `json:"item"`
ItemRev int `json:"item_rev,omitempty"`
Kind string `json:"kind"`
Section string `json:"section,omitempty"`
Quote string `json:"quote,omitempty"`
Replace string `json:"replace,omitempty"`
Text string `json:"text,omitempty"`
CreatedAt string `json:"created_at"`
}
Note is one piece of the owner's feedback on an item, not yet sent.
type Notifier ¶
type Notifier interface {
Mail(ctx context.Context, to, subject, body, ref string) error
Comment(ctx context.Context, task, text string) error
}
Notifier tells the team: a Tether message to each owner, a comment on the item's task.
type Preset ¶
type Preset struct {
ID string `json:"id"`
App string `json:"app"`
Label string `json:"label"`
Kinds []Kind `json:"kinds"`
Views []View `json:"views"`
// Templates: starting trees a new workspace can be made with (templates.go).
Templates []TemplateInfo `json:"templates,omitempty"`
}
Preset is a kind set and the views a new workspace gets.
type Published ¶
type Published struct {
At string `yaml:"at" json:"at"`
Where string `yaml:"where" json:"where"`
URL string `yaml:"url,omitempty" json:"url,omitempty"`
Note string `yaml:"note,omitempty" json:"note,omitempty"`
}
Published is one entry of an item's publication log.
type RoundNote ¶
type RoundNote struct {
ID string `yaml:"id" json:"id"`
Kind string `yaml:"kind" json:"kind"`
Section string `yaml:"section,omitempty" json:"section,omitempty"`
Quote string `yaml:"quote,omitempty" json:"quote,omitempty"`
Replace string `yaml:"replace,omitempty" json:"replace,omitempty"`
Text string `yaml:"text,omitempty" json:"text,omitempty"`
State string `yaml:"state" json:"state"` // open, done, declined
Reply string `yaml:"reply,omitempty" json:"reply,omitempty"`
}
RoundNote is a note as the round item carries it (as in story/v1).
type RoundView ¶
type RoundView struct {
Round int `json:"round"`
Ref string `json:"ref"`
SentAt string `json:"sent_at"`
ItemRev int `json:"item_rev"`
Digest string `json:"digest,omitempty"` // of the item's text when sent
Notes []RoundNote `json:"notes"`
Open int `json:"open"`
Problem string `json:"problem,omitempty"`
}
RoundView is a sent round as the team left it.
type Sent ¶
type Sent struct {
Round int `json:"round"`
Ref string `json:"ref"`
Notes int `json:"notes"`
Mailed []string `json:"mailed"`
NotMailed []string `json:"not_mailed"` // owners that are not Tether addresses, or whose mail failed
Commented string `json:"commented,omitempty"`
}
Sent is what Send round did.
type Signed ¶
type Signed struct {
SignedOff
Stage string `json:"stage,omitempty"` // the stage it moved to, if it moved
Mailed []string `json:"mailed"`
NotMailed []string `json:"not_mailed"`
Problem string `json:"problem,omitempty"`
}
Signed is what sign-off did.
type SignedOff ¶
type SignedOff struct {
At string `yaml:"at" json:"at"`
Rev int `yaml:"rev" json:"rev"` // the revision that was approved
Digest string `yaml:"digest" json:"digest"` // of its title and text: a later change makes it stale
Pinned string `yaml:"pinned,omitempty" json:"pinned,omitempty"`
Round int `yaml:"round,omitempty" json:"round,omitempty"` // the last round sent before it
}
SignedOff is the sign-off an item carries (its `signed` key).
type Space ¶
type Space struct {
Default string `json:"default_view"`
Workspace Workspace `json:"workspace"`
Kinds []Kind `json:"kinds"`
Items []Card `json:"items"`
Views []View `json:"views"`
}
Space is a workspace opened: its index, kinds, items and views.
type Stack ¶
type Stack struct {
ID string `json:"id" yaml:"id"`
Title string `json:"title" yaml:"title"`
X float64 `json:"x" yaml:"x"`
Y float64 `json:"y" yaml:"y"`
Items []string `json:"items" yaml:"items"`
Bind *Bind `json:"bind,omitempty" yaml:"bind,omitempty"`
}
Stack is a titled pile of cards.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the working copy of the Work items (the module's own store): a mirror of the Caster items for quick views and reading when Caster is away, and the owner's notes not yet sent. Nothing lives only here once it is in Caster.
Writes go to Caster at once, each after reading the item again: Caster's put has no "only if still at revision N", so a contended item (a parent's children, a view's layout, a card's stage) is re-read and the change applied to what is there, and an edit begun on an older revision does not overwrite the newer one; the owner's text is kept as a suggestion on it instead.
func NewStore ¶
NewStore is the working copy in db (the module's store, migrations/0001_init.sql) over caster. caster may be nil (no way to reach Tether): the copy is then read only and says why.
func (*Store) AddNote ¶
AddNote puts the owner's (or the agent's, for the owner) note in the item's draft round. A suggestion names the passage it replaces, which must be in that section as it is now.
func (*Store) ApplyTemplate ¶
ApplyTemplate makes a template's items in a workspace: the tree (each item in its parent's children, in order), then the links between them.
func (*Store) Cut ¶
Cut takes an item out of the views (cut: true) and out of its parent's children; it stays in Caster and can be restored.
func (*Store) EditItem ¶
EditItem writes the owner's edit as a new revision, unless the item moved on since BaseRev (then *Conflict).
func (*Store) MakeItem ¶
MakeItem makes an item of a kind the workspace has, at the stage given (or the kind's first), and puts it at the end of its parent's children when it has one.
func (*Store) Move ¶
Move sets one value on an item as it is now: its stage (key "stage") or an enum or date field (a board column, a calendar day). Nothing else of the item changes.
func (*Store) NSOf ¶
NSOf is the namespace a workspace's items are in ("" when there is no such workspace).
func (*Store) NewWorkspace ¶
func (s *Store) NewWorkspace(ctx context.Context, slug, title, preset, about string) (string, error)
NewWorkspace makes a workspace from a preset: its kinds and views in its own namespace, then its index in "work" (the index is what makes it exist). Refused when it exists.
func (*Store) Open ¶
Open is a workspace from the copy. ok is false when there is no such workspace.
func (*Store) PatchLayout ¶
PatchLayout applies p to a view's layout as it is now: one new revision of the view.
func (*Store) Place ¶
Place puts an item in the outline: under parent (an item id, or "" for the top), before the sibling before (or at the end). Moving it to another parent takes it out of the old parent's children, puts it in the new one's, and sets its parent: each applied to the item as it is now. The top level's order is kept in the outline view's layout (order), when a view is given. A parent must be of a kind that holds the item's kind, and an item cannot go inside itself.
func (*Store) Refresh ¶
Refresh brings the copy of one namespace up to date with Caster: one listing, and a fetch for each item whose revision moved. At most every 15 s per namespace unless forced.
func (*Store) SaveView ¶
SaveView changes a view as it is now: the keys given (view, title, kinds, group_by, date_field, root, rel, filter, layout); other keys stay as they are.
func (*Store) SendRound ¶
SendRound writes the item's draft round to Caster and tells the workspace's owners.
func (*Store) SendToTorque ¶
func (s *Store) SendToTorque(ctx context.Context, ws, id string) (task string, created bool, err error)
SendToTorque makes the item's Torque task, or returns the one it already has (created false). The item is read again under the store's lock, so two sends cannot make two tasks.
func (*Store) SetOwners ¶
SetOwners sets the Tether addresses a workspace's rounds and sign-offs are mailed to.
func (*Store) SignOff ¶
func (s *Store) SignOff(ctx context.Context, ws, id string, anyway bool, pin Pinner, tell Notifier) (Signed, error)
SignOff approves the item as it is now: the revision and a digest of its text are kept in the item (`signed`), an item at the review stage moves to the next one, the approved revision is pinned in CAS, and the owners are told. When the last round still has open notes, it is refused unless anyway is set. Draft notes are not sent; they stay.
func (*Store) TorqueStatus ¶
TorqueStatus reads a task's title and status from Torque.
func (*Store) UpdateWorkspace ¶
func (s *Store) UpdateWorkspace(ctx context.Context, ws string, title *string, archived, deleted *bool) error
UpdateWorkspace retains the index and Caster history even when removed from the list.
type TaskStatus ¶
type TaskStatus struct {
ID string `json:"id"`
Title string `json:"title"`
Status string `json:"status"`
}
TaskStatus is a Torque task as the detail shows it.
type TemplateInfo ¶
type TemplateInfo struct {
ID string `json:"id"`
Label string `json:"label"`
About string `json:"about"`
}
TemplateInfo is what the app offers.
type View ¶
type View struct {
ID string `yaml:"-" json:"id"`
View string `yaml:"view" json:"view"` // board | calendar | outline | canvas | flow
Title string `yaml:"title" json:"title"`
Kinds []string `yaml:"kinds" json:"kinds"`
Filter map[string]any `yaml:"filter,omitempty" json:"filter,omitempty"`
GroupBy string `yaml:"group_by,omitempty" json:"group_by,omitempty"`
DateFld string `yaml:"date_field,omitempty" json:"date_field,omitempty"`
Root string `yaml:"root,omitempty" json:"root,omitempty"`
Rel []string `yaml:"rel,omitempty" json:"rel,omitempty"`
Layout map[string]any `yaml:"layout,omitempty" json:"layout,omitempty"`
Rev int `yaml:"-" json:"rev"`
Problem string `yaml:"-" json:"problem,omitempty"`
}
View is a saved way of looking at a workspace; Layout holds a canvas or flow arrangement.
type Workspace ¶
type Workspace struct {
Archived bool `json:"archived"`
Deleted bool `json:"deleted"`
Slug string `json:"slug"`
Title string `json:"title"`
App string `json:"app"`
Preset string `json:"preset"`
NS string `json:"ns"`
Owners []string `json:"owners"`
Created string `json:"created,omitempty"`
Body string `json:"body"`
Items int `json:"items"`
Rev int `json:"rev"`
Updated string `json:"updated"`
Problem string `json:"problem,omitempty"`
}
Workspace is one body of work, from its index item.