references

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 17 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 references reads the @ references a person writes in a message, such as @file:main.go or @diff, and attaches what each names for the model: the prefixes the plugins bring, the one expansion every message goes through before the model reads it, with its limits on how many a message holds and how much of the model's window what they attach may take, and the completion of what is typed after an @

Index

Constants

View Source
const (
	SignFile   = "📄"
	SignFolder = "📁"
	SignGit    = "🧾"
	SignPage   = "🌐"
	SignOther  = "📌"
	SignOnDisk = "📎"
)

Marks the blocks of what references attach start with, by what they hold

Variables

This section is empty.

Functions

func Block

func Block(ask Ask, sign, heading, text string) string

Block of what a reference attaches as the model reads it: the mark, the heading with the tokens the text takes, then the text

Types

type Ask

type Ask struct {
	// Settings of the profile the session runs on
	Config *config.Config
	// Session the message is for, empty for none
	Session string
	// Folder the session works in: what a path is read against and must lie in
	Folder string
	// Surface the person wrote on, such as tui, telegram or cron
	Surface string
	// The person wrote in a chat app, so what the message attaches is held to what that person may reach
	Chat bool
	// Asks the person to allow what a reference needs beyond the folder, such as a file outside it; nil where nobody can be asked
	Gate func(ctx context.Context, gate tools.Gate) error
	// Tokens the session's model takes in at once
	Window int
	// Tokens of a text as the session's model counts them, nil for the estimate
	Count func(text string) int
	// Most tokens one reference may attach inline, set by the expansion: a file larger is named by where it is
	Budget int
}

Where a message is expanded and for whom, which decides what its references may reach and how much they may attach

func (Ask) Tokens

func (a Ask) Tokens(text string) int

Tokens of the text as the session's model counts them, estimated where it has no count

type Attachment

type Attachment struct {
	// The reference as it was written
	Raw  string
	Kind string
	// Tokens of what it attached, 0 for one that attached nothing
	Tokens int
	// Why it attached nothing, a sentence; empty for one that attached
	Failure string
}

What one reference of a message attached, or why it attached nothing

type Expanded

type Expanded struct {
	// Prefix of each reference that attached something, and of each that attached nothing
	Attached, Failed []string
	// The message was not sent, as what its references attached took more of the window than the settings let it
	Refused bool
	// Tokens what they attached took
	Tokens int
}

What came of the references of one message, as monitoring counts it

type Expansion

type Expansion struct {
	// What goes after the message for the model: the warnings of its references, then the blocks they attached; empty for a message
	// whose references attached nothing and raised nothing, or one with none
	Added string
	// Each reference in the order written, what it attached or why it attached nothing
	Attached []Attachment
	// Tokens of what was attached
	Tokens int
	// What was attached takes more of the model's window than the share the settings warn at, a sentence; empty when it does not
	Warning string
	// What was attached takes more of the model's window than the share the settings refuse at, so the message is not sent, a sentence
	// saying so; nothing is attached then
	Refused string
}

What the references of a message attach for the model

func (Expansion) Failures

func (e Expansion) Failures() []string

Failures of the references that attached nothing, each the reference and why

func (Expansion) Text

func (e Expansion) Text(message string) string

The message for the model: the text it is sent with what its references attached after it

type Offer

type Offer struct {
	// Text that takes the place of the word typed, such as @file:src/main.go
	Text string
	// What the row shows, the text when empty
	Display string
	// What is shown beside it, such as a size or the subject of a commit
	Meta string
}

One completion of what is typed after an @

type Prefix

type Prefix struct {
	// Word after the @, lower case letters, digits, dashes and underscores, starting with a letter, such as file
	Name string
	// What a reference with it attaches, a short phrase completion shows beside it: "A file of the folder"
	About string
	// The prefix written as a person types it, such as @git:5, which completion and help show; @name: or @name when empty
	Example string
	// What brings it, as a person reads it, such as icebath or the extension jira
	From string
	// Written alone, with no value after a colon, as @diff is
	Bare bool
	// Takes a line range after its value, as @file:main.go:10-20 does
	Lines bool
	// The block the reference attaches, made with Block, or an error saying in a sentence why it attaches nothing
	Expand func(ctx context.Context, ask Ask, ref Reference) (string, error)
	// Values that complete what is typed after the prefix, each offer's text the whole reference; nil for a prefix that completes none
	Complete func(ctx context.Context, ask Ask, typed string, limit int) []Offer
	// References a word typed after an @ with no prefix matches, such as the files of the folder whose names hold it; nil for none
	Matches func(ctx context.Context, ask Ask, typed string, limit int) []Offer
	// Why its references attach nothing for the profile of the settings and what to do about it, whole sentences in a person's words,
	// such as "git is not installed. Install git to attach diffs."; empty when they can, nil for a prefix that always can
	Lacks func(cfg *config.Config) string
}

A prefix a registrant brings: what a reference written with it attaches, and what completes it

func (Prefix) Written

func (p Prefix) Written() string

The prefix as a person types it

type Reference

type Reference struct {
	// As it was written, such as @file:"my notes.md":3-9, the punctuation of the sentence after it left out
	Raw string
	// Prefix it was written with, lower case, such as file or diff
	Kind string
	// What follows the prefix, its quotes and escapes taken off and a line range left out; empty for a prefix that takes nothing
	Target string
	// First and last line of the range a reference names, 0 for none
	Start, End int
	// Where it starts and ends in the message, in bytes
	At, Ends int
}

A reference of a message, as it was written

func Parse

func Parse(text string, known map[string]Prefix) []Reference

The references of the text by the prefixes known, in the order written. A bare prefix is written @name, any other @name:value, its value a quoted text on one line or the run of what is no space, a space after a backslash taken into it; an @ right after a letter, a digit, an underscore or a slash starts none, as in an address or a path. A prefix that takes a line range ends its value with :start or :start-end

type References

type References struct {
	Registry
	// contains filtered or unexported fields
}

The references of messages: the prefixes the plugins bring, and the one expansion every message goes through

func New

func New(cfg *config.Config) *References

func (*References) Complete

func (h *References) Complete(ctx context.Context, ask Ask, word string, limit int) []Offer

What a word typed after an @ completes to, at most limit: the prefixes it starts, and with a word long enough the references it matches with no prefix, such as files whose names hold it; once a prefix is typed with its colon, the values it completes

func (*References) Conflicts

func (h *References) Conflicts(cfg *config.Config) []string

Why each prefix a plugin brings is not read, a sentence each, none when every one is

func (*References) Expand

func (h *References) Expand(ctx context.Context, ask Ask, written string) Expansion

What the references of the message as the person wrote it attach, each expanded at the same time as the others, the first ones the settings allow alone: every block made with the session's budget, every failure said for the model and kept for the person, and nothing at all once what they attach takes more of the window than the share the settings refuse at

func (*References) Holds

func (h *References) Holds(cfg *config.Config, text string) bool

Whether the text holds a reference a message of the profile expands, read without I/O

func (*References) Known

func (h *References) Known(cfg *config.Config) []Prefix

Prefixes a message of the profile of the settings reads, in the order they were registered: of two of one name the first, a prefix whose name is no such word or that expands nothing left out

func (*References) Observing

func (h *References) Observing(observe func(Expanded))

Hands every message expanded from now on to observe, such as monitoring's count of them; observe never blocks

func (*References) Register

func (h *References) Register(registrant Registrant)

Adds a registrant; a registry nested in the host reaches it through Host

func (*References) Stripped

func (h *References) Stripped(cfg *config.Config, text string) string

The text without its references that name something after a colon, such as @file:main.go, for what reads what a message is about, such as its title; a bare one such as @diff stays a word of it

func (*References) Tally

func (h *References) Tally() Tally

What came of the references of the messages expanded since icebath started

type Registrant

type Registrant interface {
	// Prefixes of the profile of the settings, read quickly, no I/O here
	Prefixes(cfg *config.Config) []Prefix
}

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

func (*Registry) Host

func (r *Registry) Host() *References

Host the registry is nested in, through which plugins expand the references of a message and complete them

func (*Registry) Prefixes

func (r *Registry) Prefixes(cfg *config.Config) []Prefix

func (*Registry) Register

func (r *Registry) Register(registrant Registrant)

type Tally

type Tally struct {
	// Messages that held references
	Messages int
	// References that attached something, and those that attached nothing
	Attached, Failed int
	// Messages not sent, as what their references attached took too much of the model's window
	Refused int
}

What came of the references of the messages expanded since icebath started

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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