libshare

package
v0.1.5542 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package libshare shares the Library's rules and sets of instructions on usemagpie.ai (site/libshares.js): a link anyone can open, and the Rules and Instructions markets, the ones shared there publicly, which the Library's Rules and Instructions tabs open.

What goes out is the rule's name, the files it is for and its text, or the set's name and text: never the agents it is given to, a file of the user's own it is kept in, or anything else of the library. Text holding what looks like a key or token is refused (redact.Scrub). The user shares, never an agent, and nothing is sent by itself but the ids of the shared items imported here (Report, with the usage stats).

shared-library.json, in magpie's folder and readable by the user alone, keeps the link of each item the user shared and the token that updates it or takes it down (usemagpie.ai keeps the token only hashed), and the link each imported item came from.

Index

Constants

View Source
const (
	Rules        = "rules"
	Instructions = "instructions"
)

The kinds shared, as usemagpie.ai's paths name them.

Variables

View Source
var ErrGone = errors.New("this was taken down on usemagpie.ai")

ErrGone is a shared item usemagpie.ai doesn't have: taken down by its author, or on a report.

View Source
var ErrOff = errors.New("sharing is off here")

ErrOff is sharing with no site to share on (a test that named none).

View Source
var ErrSecret = errors.New("the text holds what looks like a key or token: take it out before sharing")

ErrSecret is text that holds what looks like a key or token.

View Source
var Site = func() string {
	if s := os.Getenv("MAGPIE_SHARE_SITE"); s != "" {
		return strings.TrimRight(s, "/")
	}
	if testing.Testing() {
		return ""
	}
	return "https://usemagpie.ai"
}

Site is where they are shared. MAGPIE_SHARE_SITE moves it, as it moves shared groups and artifacts, and a test names its own: a test never reaches the real site.

Functions

func Forget

func Forget(kind string, names []string) error

Forget is what removing rules or sets leaves behind: where they came from is dropped, and the links they were shared at are set aside (Retired), so one made later under the same name shares at a link of its own. Nothing is written when none is recorded.

func Imported

func Imported(key string, page Page) error

Imported records that the item key names here came from page.

func Key

func Key(kind, name string) string

Key is the record's key of a rule's name or a set's id.

func Like

func Like(ctx context.Context, install, id string, on bool) (int, error)

Like likes shared item id, or unlikes it, from install (this computer's random id, stats.InstallID): its likes after.

func LinkID

func LinkID(text string) (kind, id string)

LinkID is the kind and id of the shared item in text: a link to its page (https://usemagpie.ai/r/<id> for a rule, /i/<id> for instructions) or a magpie://rule?id=<id> or magpie://instructions?id= link; "" for anything else.

func Renamed

func Renamed(kind, old, name string) error

Renamed carries what is recorded of a rule or set from its old name to its new one: the link it is shared at, and where it came from.

func Report

func Report(ctx context.Context, install string) error

Report tells usemagpie.ai the shared items imported here that are still here, from install, for the markets' counts: with the usage stats, and never when the user turned those off.

func Unpublish

func Unpublish(ctx context.Context, kind, name string) error

Unpublish takes the shared link of the rule or set name down; one not shared, or taken down already, is done.

func ValidID

func ValidID(id string) bool

ValidID reports whether id is a shared item's id on usemagpie.ai.

Types

type Card

type Card struct {
	ID          string   `json:"id"`
	URL         string   `json:"url"`
	Title       string   `json:"title"`
	Description string   `json:"description,omitempty"`
	Author      string   `json:"author,omitempty"`
	Version     int      `json:"version"`
	Updated     int64    `json:"updated,omitempty"`
	Name        string   `json:"name,omitempty"`
	Paths       []string `json:"paths,omitempty"`
	Excerpt     string   `json:"excerpt,omitempty"`
	Chars       int      `json:"chars,omitempty"`
	Uses        int      `json:"uses,omitempty"`
	Likes       int      `json:"likes,omitempty"`
	Mine        bool     `json:"mine,omitempty"`
	Imported    string   `json:"imported,omitempty"`
	Liked       bool     `json:"liked,omitempty"`
}

Card is an item in a market.

type From

type From struct {
	ID      string    `json:"id"`
	Version int       `json:"version"`
	Title   string    `json:"title,omitempty"`
	At      time.Time `json:"at"`
}

From is the shared item one here was imported from.

type InstrItem

type InstrItem struct {
	Name string `json:"name"`
	Text string `json:"text"`
}

InstrItem is a set of instructions shared.

type Item

type Item struct {
	Magpie       string     `json:"magpie"` // "rule" or "instructions"
	Version      int        `json:"version"`
	Rule         *RuleItem  `json:"rule,omitempty"`
	Instructions *InstrItem `json:"instructions,omitempty"`
}

Item is a rule or a set of instructions as it is shared: the body usemagpie.ai keeps.

func Public

func Public(kind, name string) (Item, error)

Public is what Publish sends of the rule called name or the set of instructions with id name: for the user to see before it goes.

type Market

type Market struct {
	Items []Card `json:"items"`
	More  bool   `json:"more,omitempty"`
}

Market is a page of a market.

func List

func List(ctx context.Context, kind, sort, q string, page int) (Market, error)

List is a page of kind's market: sort "top" or "new", q what the user searches for.

type Meta

type Meta struct {
	Title       string `json:"title"`
	Description string `json:"description,omitempty"`
	Author      string `json:"author,omitempty"`
	// Public lists it in the market; unlisted, only its link opens it
	Public bool `json:"public"`
}

Meta is what the user says of an item they share.

type Mine

type Mine struct {
	Meta
	ID      string    `json:"id"` // on usemagpie.ai
	URL     string    `json:"url"`
	Token   string    `json:"token,omitempty"`
	Version int       `json:"version"`
	At      time.Time `json:"at"`
}

Mine is an item the user shared.

func Publish

func Publish(ctx context.Context, kind, name string, meta Meta) (Mine, error)

Publish shares the rule or set name on usemagpie.ai as Public has it, with meta: at a new link, or, shared already, at its link as its next version.

type Page

type Page struct {
	ID          string `json:"id"`
	URL         string `json:"url"`
	Kind        string `json:"kind"`
	Title       string `json:"title"`
	Description string `json:"description,omitempty"`
	Author      string `json:"author,omitempty"`
	Public      bool   `json:"public"`
	Version     int    `json:"version"`
	Updated     int64  `json:"updated,omitempty"`
	Item        Item   `json:"item"`
	Uses        int    `json:"uses,omitempty"`
	Likes       int    `json:"likes,omitempty"`
	// Liked here, and Imported: the key of the item here imported from
	// it (filled in by Fetch, not the site)
	Liked    bool   `json:"liked,omitempty"`
	Imported string `json:"imported,omitempty"`
	Mine     bool   `json:"mine,omitempty"`
	// Free: for a rule, a name it can be added under here, its own or
	// its own with -2, -3… (filled in by the page's API)
	Free string `json:"free,omitempty"`
}

Page is a shared item as usemagpie.ai has it.

func Fetch

func Fetch(ctx context.Context, kind, id string) (Page, error)

Fetch is shared item id of kind.

type Retired

type Retired struct {
	Mine
	Key  string    `json:"key"`
	Gone time.Time `json:"gone"`
}

Retired is the link an item removed from the library was shared at: kept with its token, so it is never lost, while one made later under the same name shares at a link of its own. The link stays up.

type RuleItem

type RuleItem struct {
	Name  string   `json:"name"`
	Paths []string `json:"paths,omitempty"`
	Body  string   `json:"body"`
}

RuleItem is a rule shared.

type State

type State struct {
	Shared map[string]Mine `json:"shared"`
	From   map[string]From `json:"from"`
	Liked  []string        `json:"liked"`
}

State is what the Library's tabs show of sharing: the items the user shared, with no token, and where those imported came from, by key, of the items still here.

func Now

func Now() State

Now is the State.

Jump to

Keyboard shortcuts

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