Help us shape the future of Go! Take the 2026 Go Developer Survey

ratchet

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package ratchet stores project rules recorded from agent failures (issue #249): each rule keeps the incident that caused it and an expiry date or review condition, so stale rules can be pruned as models improve. Rules live in <cwd>/.tinyagent/ratchet.toml; a project without the file pays nothing. Active rules become guidance at run start, and a rule with a deny matcher is also enforced as a permissions deny rule.

Index

Constants

View Source
const (
	DefaultCommandTools = "bash|start_process"
	DefaultPathTools    = "write_file|edit_file|apply_patch"
	DefaultHostTools    = "web_fetch"
)

Default tools a deny matcher applies to when tool is left empty.

View Source
const DateLayout = "2006-01-02"

DateLayout is the format of created and expires.

View Source
const DefaultExpiryDays = 90

DefaultExpiryDays is how long a rule recorded without --ratchet-expires or --ratchet-review stays active.

View Source
const RelPath = ".tinyagent/ratchet.toml"

RelPath is the rules file relative to --cwd.

Variables

This section is empty.

Functions

func Path

func Path(root string) string

Path returns the rules file for root.

func PermissionRules

func PermissionRules(active []Rule) []config.PermissionRule

PermissionRules returns a deny rule for each active rule with a matcher.

func Remove

func Remove(path, id string) error

Remove deletes the rule with id from path.

func Section

func Section(active []Rule) string

Section renders active rules as a system prompt section, or "" for none.

Types

type Deny

type Deny struct {
	Tool    string `toml:"tool,omitempty"`
	Command string `toml:"command,omitempty"`
	Path    string `toml:"path,omitempty"`
	Host    string `toml:"host,omitempty"`
}

Deny is an enforceable matcher with the permissions rule syntax. At most one of Command, Path and Host may be set.

type Rule

type Rule struct {
	// ID is r1, r2, ...; assigned by Add.
	ID string `toml:"id"`
	// Rule is the guidance shown to the model.
	Rule string `toml:"rule"`
	// Incident is what went wrong and led to the rule.
	Incident string `toml:"incident"`
	// Created is the YYYY-MM-DD date the rule was recorded.
	Created string `toml:"created"`
	// Expires is the YYYY-MM-DD date from which the rule is skipped.
	Expires string `toml:"expires,omitempty"`
	// Review is a condition under which the rule should be reconsidered.
	Review string `toml:"review,omitempty"`
	// Deny, when set, also enforces the rule as a permissions deny rule.
	Deny *Deny `toml:"deny,omitempty"`
}

Rule is one recorded rule.

func Add

func Add(path string, r Rule, now time.Time) (Rule, error)

Add appends r to the rules in path, creating the file and its directory when needed. It assigns the next id and today's created date, and with no expires and no review sets expires DefaultExpiryDays from now.

func Load

func Load(path string) ([]Rule, error)

Load reads the rules in path. A missing file is no rules and no error. Errors name the rule's position.

func Split

func Split(rules []Rule, today time.Time) (active, expired []Rule)

Split separates rules into active and expired as of today, keeping order.

func (Rule) Expired

func (r Rule) Expired(today time.Time) bool

Expired reports whether r's expiry date is on or before today.

func (Rule) Validate

func (r Rule) Validate() error

Validate checks a rule's fields.

Jump to

Keyboard shortcuts

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