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

maskrec

package
v0.1.2125 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package maskrec keeps the record of what masking swapped for placeholders before a request went to a vendor, for Settings → Privacy to show: which kinds, found by which finder, going to whom.

A value itself is never written down. A record holds each value's placeholder, its kind, its finder, and a hint (its first character or a key's prefix, and its length). The value behind a placeholder is known only to the masker's memory while magpie runs (gwmw.Teller.Value), and the text around it as the vendor saw it is kept in memory only, for the latest records.

A day is a file of its own, one request a line, under ~/.config/magpie/masking, kept keepDays days and keepBytes in all.

Index

Constants

View Source
const SentMax = sentMax

SentMax is the longest request a record keeps as sent; a longer one is kept as nothing, so a caller need not copy it.

Variables

View Source
var Dir = func() string { return filepath.Join(appdir.Config(), "masking") }

Dir is where the days are kept.

Functions

func Clear added in v0.1.1593

func Clear() error

Clear deletes every record kept: each day's file, and what memory has of them (their snips, the requests' text). A day goes whole, never rewritten, so nothing is left half-cleared for a reader; a request still going is written to a new day's file once it is done. A day that can't be removed stays, and is named in the error. What a placeholder stood for is the masker's, in memory alone, and stays there for the answers still to come.

func Restored added in v0.1.1392

func Restored(key int64, put map[string]int)

Restored tells the record of key what its answer put back: by placeholder, the places. Memory only, as the snips are.

func SentOf added in v0.1.1392

func SentOf(key int64) (string, bool)

SentOf is the request of key as the vendor got it, while memory keeps it.

Types

type Count

type Count struct {
	Name     string `json:"name"`
	N        int    `json:"n"`
	Distinct int    `json:"distinct"`
}

Count is a kind's, an agent's or a provider's share.

type Day

type Day struct {
	Day      string `json:"day"`
	Requests int    `json:"requests"`
	N        int    `json:"n"`        // values swapped, each place counted
	Distinct int    `json:"distinct"` // different values
}

Day is one day's count.

type Filter

type Filter struct {
	Kind, By, Agent, Provider string
	Blocked                   bool
}

Filter narrows List: by kind (one, or several split by commas), by finder, by agent or provider, "" is any; Blocked keeps only the requests masking held back.

type Record

type Record struct {
	Key      int64     `json:"key"` // unique, later records larger
	Time     time.Time `json:"t"`
	Route    int64     `json:"route,omitempty"` // its route in the trace, where it has one
	What     string    `json:"what"`            // chat, search, image, video, embeddings, audio, count
	Agent    string    `json:"agent,omitempty"`
	Session  string    `json:"session,omitempty"`
	Provider string    `json:"provider,omitempty"`
	Model    string    `json:"model,omitempty"`
	N        int       `json:"n"` // values swapped, each place counted
	Values   []Value   `json:"values,omitempty"`
	// Blocked: the request was held back, sent to no one, for a value
	// of a kind the user set to block
	Blocked bool `json:"blocked,omitempty"`
	// Snips: by placeholder, the text around its first place as the
	// vendor saw it; in memory only
	Snips map[string]string `json:"snips,omitempty"`
	// Took is how long masking the request took, in microseconds
	Took int64 `json:"took,omitempty"`
	// Back: by placeholder, the places the answer had it put back; in
	// memory only, told once the answer is done (Restored)
	Back map[string]int `json:"back,omitempty"`
	// Sent is the request as the vendor got it; in memory only, for the
	// latest keepSent, and never in a list (SentOf)
	Sent string `json:"-"`
}

Record is one request's masking.

func Add

func Add(r Record) Record

Add records r, its Values made from hits as they came: one for each placeholder, counted. It returns r as recorded. Errors are swallowed: keeping the record must never break a request.

func Get

func Get(key int64) (Record, bool)

Get is the record of key, with its snips while memory has them.

func Hold added in v0.1.1574

func Hold(r Record) (Record, func(provider, model string))

Hold is Add for a request whose provider isn't known yet: a group's member that fails passes it to the next, so the one it is planned for may never get it (Max You and Linka on Discord: the records named the group's first member, which no request had reached). r is in memory at once, for its route's badge and the answer's Restored, and goes on disk, where the summary counts it, once done is told the provider and model that had it last ("" keeps r's). Only done's first call counts.

func List

func List(before int64, limit int, f Filter) ([]Record, bool)

List is up to limit records before key (0: the latest), newest first, that f takes, and whether there are more.

func OfRoute

func OfRoute(id int64) (Record, bool)

OfRoute is the record of the trace's route id, while memory has it.

type Seen

type Seen struct {
	Placeholder string    `json:"p"`
	Kind        string    `json:"kind"`
	By          string    `json:"by"`
	Head        string    `json:"head,omitempty"`
	Len         int       `json:"len"`
	N           int       `json:"n"`
	Requests    int       `json:"requests"`
	Last        time.Time `json:"last"`
}

Seen is one different value, as the record has it.

type Summary

type Summary struct {
	Days      []Day          `json:"days"` // oldest first, each day of them
	Requests  int            `json:"requests"`
	N         int            `json:"n"`
	Distinct  int            `json:"distinct"`
	Warned    int            `json:"warned,omitempty"`  // places a value went as written, the user told
	Blocked   int            `json:"blocked,omitempty"` // requests held back
	Hours     [24]int        `json:"hours"`             // places, by the hour of the day
	Kinds     []Count        `json:"kinds"`
	By        map[string]int `json:"by"` // different values by the finder that found each
	Agents    []Count        `json:"agents"`
	Providers []Count        `json:"providers"`
	Values    []Seen         `json:"values"` // the most masked first, at most topValues
	Since     string         `json:"since,omitempty"`
}

Summary is what masking did over some days.

func Sum

func Sum(days int) Summary

Sum is the summary of the days days up to today.

type Value

type Value struct {
	Placeholder string `json:"p"`
	Kind        string `json:"k"`
	By          string `json:"b"`           // the finder: rule, yours, word, model or known
	Head        string `json:"h,omitempty"` // its first character, or a key's prefix
	Len         int    `json:"l"`           // its length in characters
	N           int    `json:"n"`           // the places the request had it
	// Action: "" masked, "warn" sent as written (the user asked to be
	// told only), "block" masked and the request held back
	Action string `json:"a,omitempty"`
}

Value is one value a request had masked, as often as it had it.

func Fresh added in v0.1.1969

func Fresh(r Record) []Value

Fresh are the values r masked that no record before it had: masked for the first time. A value sent as written (Action "warn") is not one masked. r is a record as Hold returned it, its Key set.

Jump to

Keyboard shortcuts

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