naming

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package naming provides primitives for parsing and formatting agent references in the form "name@pub8", where pub8 is the first 8 hex characters of the publisher's public-key fingerprint.

This package ships only the parser + formatter; threading through daemon state/trigger/cron is deferred to later tasks to keep the blast radius minimal.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidAgentRef is returned when the agent reference string
	// cannot be parsed at all (multiple @ signs, empty string, etc.).
	ErrInvalidAgentRef = errors.New("invalid agent reference")

	// ErrInvalidName is returned when the agent name part fails validation.
	ErrInvalidName = errors.New("invalid agent name")

	// ErrInvalidPub8 is returned when the pub8 suffix is not exactly 8
	// lowercase hex characters.
	ErrInvalidPub8 = errors.New("invalid pub8: must be exactly 8 hex characters")
)

Sentinel errors returned by ParseAgentRef and the validation functions.

Functions

func FormatAgentRef

func FormatAgentRef(name string, fingerprint string) string

FormatAgentRef formats an agent reference string from a name and a full fingerprint (64 hex chars).

If fingerprint is non-empty, the first 8 hex characters are used as the pub8 suffix: "name@<first-8>". The pub8 is always lowercased.

If fingerprint is empty, the result is the bare agent name.

Examples:

FormatAgentRef("weather", "a1b2c3d4e5f6...")  → "weather@a1b2c3d4"
FormatAgentRef("weather", "")                  → "weather"

func ParseAgentRef

func ParseAgentRef(s string) (name string, pub8 string, err error)

ParseAgentRef parses an agent reference string of the form "name" or "name@pub8".

Accepted forms:

  • "name" → bare agent name
  • "name@<8-hex>" → agent name with pub8 suffix

The pub8 suffix is normalized to lowercase before being returned. The name part is validated via ValidateName.

Errors (wrapping ErrInvalidAgentRef):

  • Empty string
  • Multiple @ separators
  • @ at start (empty name)
  • Empty pub8 after @
  • pub8 not exactly 8 hex characters
  • Name fails ValidateName

func ValidateName

func ValidateName(name string) error

ValidateName checks whether the given string is a valid agent name.

Agent names must be 1–63 characters long and must match the pattern [a-z0-9]([a-z0-9-]*[a-z0-9])? — no uppercase, no leading/trailing hyphens, no empty string.

func ValidatePub8

func ValidatePub8(pub8 string) error

ValidatePub8 checks whether the given string is a valid pub8 suffix. A valid pub8 is exactly 8 lowercase hex characters ([0-9a-f]).

Types

This section is empty.

Jump to

Keyboard shortcuts

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