rules

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package rules holds the rules a board enforces on every write: role permissions, policy presets, who a message is addressed to, and who may read it. It is pure logic with no storage, so every rule can be tested directly.

Index

Constants

View Source
const (
	Post        = "post"
	Broadcast   = "broadcast"
	Urgent      = "urgent"
	CreateTasks = "create_tasks"
	ClaimTasks  = "claim_tasks"
	WriteNotes  = "write_notes"
	UploadFiles = "upload_files"
	Invite      = "invite"
	AddPeople   = "add_people"
	EditCharter = "edit_charter"
)

Permissions a role can grant.

View Source
const (
	Starter     = "starter"
	Recommended = "recommended"

	VisibilityOpen      = "open"
	VisibilityAddressed = "addressed"

	Everyone = "everyone"
	Granted  = "granted"
)

Policy values.

View Source
const (
	AccessAdmin  = "admin"
	AccessMember = "member"
)

Access levels of a person on a board. An admin may change the board's charter, roles, policy and monitor settings; a member may act only on their own agents. Agents have no access level.

View Source
const (
	TargetAll   = "all"
	TargetName  = "name"
	TargetRole  = "role"
	TargetOwner = "owner"
)

Target kinds in a message's `to` list.

View Source
const MemberRole = "member"

MemberRole is the role every board has.

Variables

Permissions lists every permission, in the order the board file schema gives them.

Functions

func AddressedTo

func AddressedTo(to []string, m Member) bool

AddressedTo reports whether a message sent to `to` is addressed to m.

func AgentNameBase

func AgentNameBase(harness, role string) string

AgentNameBase is the name a new agent gets before a number is added: its harness's short name when the harness is known, otherwise its role.

func AllocateName

func AllocateName(base string, taken func(string) bool) string

AllocateName returns base if it is free, otherwise base-2, base-3, and so on.

func AllocateNumberedName

func AllocateNumberedName(base string, taken func(string) bool) string

AllocateNumberedName returns the first free base-1, base-2, and so on: neutral names that say nothing about the agent.

func CanManage

func CanManage(person, agent Member) bool

CanManage reports whether person may pause or remove agent: only the agent's owner or an admin of its board may.

func CanRead

func CanRead(p Policy, to []string, senderID string, reader Member, recorded ...[]string) bool

CanRead reports whether reader may read a message from senderID to `to` on a board with policy p. Humans read everything; under addressed visibility, agents read only what they sent or what was addressed to them. Owner targets use recorded IDs.

func NormalizeName

func NormalizeName(s string) string

NormalizeName turns a login or display name into a valid member name: lowercase letters, digits and dashes, at most 40 characters.

func ParseTarget

func ParseTarget(t string) (kind, value string, ok bool)

ParseTarget splits all, @name, role:R or owner:handle into its kind and value.

Types

type Grant

type Grant struct {
	Permission string
	TaskTypes  []string
}

Grant is one entry in a role's `can` list: a permission, or claim_tasks limited to some task types.

func (Grant) MarshalJSON

func (g Grant) MarshalJSON() ([]byte, error)

MarshalJSON writes a plain permission as a string and a limited one as an object.

func (*Grant) UnmarshalJSON

func (g *Grant) UnmarshalJSON(b []byte) error

UnmarshalJSON reads either form.

func (*Grant) UnmarshalYAML

func (g *Grant) UnmarshalYAML(n *yaml.Node) error

UnmarshalYAML reads either form from a board file.

type Member

type Member struct {
	ID      string
	Name    string
	Kind    string // "agent" or "human"
	Role    string // empty for humans
	HumanID string // the person, or the agent's owner
	Access  string // AccessAdmin or AccessMember for a person, empty for an agent
}

Member is what the rules need to know about a board member.

func (Member) IsAdmin

func (m Member) IsAdmin() bool

IsAdmin reports whether the member is a person who may change the board's rules.

func (Member) IsHuman

func (m Member) IsHuman() bool

IsHuman reports whether the member is a person.

type Policy

type Policy struct {
	Nudges     string `json:"nudges"`
	Preset     string `json:"preset"`
	Visibility string `json:"visibility"`
	Broadcast  string `json:"broadcast"`
	Urgent     string `json:"urgent"`
	// ShowHarness lets agents see which harness other agents run. When false, new
	// agents without a chosen name get neutral names.
	ShowHarness bool     `json:"show_harness"`
	Overrides   []string `json:"overrides"`
}

Policy is what the server enforces on a board.

func Preset

func Preset(name string) (Policy, error)

Preset returns the policy a preset stands for.

func (Policy) Apply

func (p Policy) Apply(c PolicyChange) (Policy, error)

Apply returns the policy after a change. A preset in the change replaces every key; individual keys then override it and are listed in Overrides when they differ from the preset.

func (*Policy) UnmarshalJSON

func (p *Policy) UnmarshalJSON(b []byte) error

UnmarshalJSON defaults missing show_harness to true and nudges to on.

type PolicyChange

type PolicyChange struct {
	Nudges     string `json:"nudges,omitempty" yaml:"nudges"`
	Preset     string `json:"preset,omitempty" yaml:"preset"`
	Visibility string `json:"visibility,omitempty" yaml:"visibility"`
	Broadcast  string `json:"broadcast,omitempty" yaml:"broadcast"`
	Urgent     string `json:"urgent,omitempty" yaml:"urgent"`
	// ShowHarness is nil when the change leaves it alone.
	ShowHarness *bool `json:"show_harness,omitempty" yaml:"show_harness"`
}

PolicyChange is a request to change a board's policy: an optional preset, then optional individual keys on top of it.

type Refusal

type Refusal string

Refusal says which permission a post lacks.

const (
	NeedsPost      Refusal = "post"
	NeedsBroadcast Refusal = "broadcast"
	NeedsUrgent    Refusal = "urgent"
)

Reasons a post is refused.

func CheckPost

func CheckPost(p Policy, role Role, sender Member, to []string, urgent bool) Refusal

CheckPost decides whether sender may post to `to` with the urgent flag. Humans may always post. It returns "" when the post is allowed.

type Role

type Role struct {
	Charter string  `json:"charter,omitempty" yaml:"charter"`
	Can     []Grant `json:"can" yaml:"can"`
}

Role is a named set of permissions with its own charter text.

func DefaultMemberRole

func DefaultMemberRole() Role

DefaultMemberRole is the `member` role when a board doesn't define it.

func (Role) Has

func (r Role) Has(p string) bool

Has reports whether the role grants permission p in any form.

Jump to

Keyboard shortcuts

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