inputsyntax

package
v0.156.1 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package inputsyntax highlights reserved tokens in the chat input field. It is a small, extensible parser: each token class (skill "/x", shortcut "/x", file ref "@x", and - in future - issue ref "#365") is described by a Rule, and a Highlighter paints every matching token with that rule's theme color.

The package is intentionally pure: it imports only regexp/strings and receives color resolution and rendering as function values, so it never depends on the UI theme/style packages and is unit-testable without asserting raw ANSI.

Highlighter.Highlight runs over an ALREADY-rendered string (after wrapping and cursor insertion). That is safe because token sigils ('/', '@', '#') never appear inside ANSI escape sequences ("\x1b[...m"), so a boundary-anchored match can never land inside an escape. A token split by the cursor or a wrap newline yields a partial body that fails the rule's Validate and is left unstyled.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Highlighter

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

Highlighter applies an ordered set of rules to an already-rendered string.

func New

func New(rules []Rule, colorOf func(key string) string, render func(text, hexColor string) string) *Highlighter

New builds a Highlighter. colorOf resolves a theme color key to a hex color and render styles text with that color (e.g. styleProvider.GetThemeColor and styleProvider.RenderWithColor). rules may be empty, making Highlight a no-op.

func (*Highlighter) Highlight

func (h *Highlighter) Highlight(s string) string

Highlight runs every rule over s and returns the styled string. Rules are applied in order; since each rule already styles only genuine plain-text tokens (an earlier rule's ANSI moves a token's sigil off the boundary), the ordering matters only for tokens sharing a sigil (skills before shortcuts).

type Kind

type Kind int

Kind identifies a class of reserved input token.

const (
	// KindSkill is a "/<name>" token that routes to an installed agent skill.
	KindSkill Kind = iota
	// KindCatalogSkill is a "/<name>" token naming a catalog skill that is not
	// installed locally yet - invoking it downloads the skill first.
	KindCatalogSkill
	// KindShortcut is a "/<name>" token that maps to a chat shortcut command.
	KindShortcut
	// KindFileRef is an "@<path>" token expanded into file content.
	KindFileRef
	// KindIssueRef is a "#<number>" token (reserved for future use).
	KindIssueRef
)

type Rule

type Rule struct {
	Kind     Kind
	Re       *regexp.Regexp
	Sigil    byte
	ColorKey string
	Validate func(name string) bool
}

Rule describes one token class: how to find it, whether a given body is a real reference, and which theme color key to paint it with.

Regex contract: exactly two capture groups.

group 1 = the leading boundary (start-of-string or a single whitespace rune),
          re-emitted UNSTYLED (Go's regexp has no lookbehind).
group 2 = the full token INCLUDING its sigil (e.g. "/plan", "@a/b", "#365").

Sigil must be the first byte of group 2.

func CatalogSkillRule added in v0.155.0

func CatalogSkillRule(validate func(name string) bool) Rule

CatalogSkillRule highlights "/<skill>" tokens naming a catalog skill that is not installed yet, in a distinct color from an installed skill. validate must be disjoint from SkillRule's (installed vs not), so rule order is irrelevant; both still come before ShortcutRule.

func FileRefRule

func FileRefRule(validate func(name string) bool) Rule

FileRefRule highlights "@<path>" tokens. validate reports whether the path is a real, accessible file (typically fileService.ValidateFile == nil).

func IssueRefRule

func IssueRefRule(validate func(name string) bool) Rule

IssueRefRule highlights "#<number>" tokens. validate may be nil to style any "#<digits>" token. Reserved for future use.

func ShortcutRule

func ShortcutRule(validate func(name string) bool) Rule

ShortcutRule highlights "/<shortcut>" tokens. validate resolves a shortcut name to a registered shortcut (typically registry.Get). Apply AFTER SkillRule.

func SkillRule

func SkillRule(validate func(name string) bool) Rule

SkillRule highlights "/<skill>" tokens. validate resolves a lowercased skill name to a loaded skill (typically skillsService.Get).

Jump to

Keyboard shortcuts

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