mention

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package mention parses @-mention tokens from prompt text. It does no I/O.

A Token is a syntactic candidate; only the session layer turns tokens into verified Mentions (working-directory containment for paths, same-workspace lookup for sessions).

Index

Constants

View Source
const (
	// MaxCandidateTokens bounds how many candidate tokens one prompt examines.
	MaxCandidateTokens = 200
	// MaxPathMentions bounds distinct file/folder targets resolved per prompt.
	MaxPathMentions = 50
	// MaxSessionMentions bounds distinct session targets resolved per prompt.
	MaxSessionMentions = 16
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Kind

type Kind string

Kind names what a verified mention points at.

const (
	// KindFile is a regular file under the target session's working directory.
	KindFile Kind = "file"
	// KindFolder is a directory under the target session's working directory.
	KindFolder Kind = "folder"
	// KindSession is another session of the target session's workspace and profile.
	KindSession Kind = "session"
)

type Mention

type Mention struct {
	Kind   Kind   `json:"kind"`
	Token  string `json:"token"`
	Target string `json:"target"` // relative path (folders end in "/") or session id
	Label  string `json:"label"`  // file/folder name or session title at admission
	Start  int    `json:"start"`
	End    int    `json:"end"`
}

Mention is a resolved, verified token.

func Reconcile

func Reconcile(text string, admitted []Mention) []Mention

Reconcile narrows admitted mentions to those whose exact Token still parses as a token in text, typically after an input.pre_submit hook rewrite (Business Rule 9). Hooks can never add mentions, so the result is always a subset of admitted.

Surviving mentions keep their admitted offsets: those point into the authored text, which is what the transcript displays and renders chips over, even when a hook rewrote the delivered message.

Repeated tokens pair in order: each occurrence of a token in text keeps one admitted mention carrying it, earliest first, and surplus admitted entries drop. The result keeps admitted order.

type Token

type Token struct {
	Raw       string // exact text, e.g. `@"docs/My Notes.md"` or `@session:sess-9f8e7d`
	Path      string // unquoted path for path tokens; empty for session tokens
	SessionID string // for session tokens
	Start     int    // UTF-16 offset, inclusive
	End       int    // UTF-16 offset, exclusive
}

Token is a syntactic candidate; it is not a mention until resolved.

func Parse

func Parse(text string) []Token

Parse returns the candidate mention tokens of text in text order, at most MaxCandidateTokens of them.

Grammar (Business Rules 1–3 and 7):

  • A token starts with `@` at offset 0 or right after a Unicode whitespace rune, outside inline code spans and fenced code blocks. Emails such as `me@example.com` and `(@x)` therefore never start a token.
  • Quoted form `@"path with spaces"` ends at the closing `"` on the same line; the text after the closing quote is plain text. An unterminated quote or an empty quoted path (`@""`) is not a token. The quoted form is always a path token, even when it reads `@"session:x"`.
  • Unquoted form ends at the next whitespace (or the start of a code span) and has trailing `.` `,` `;` `:` `!` `?` `)` `]` `}` `'` `"` trimmed. A bare `@`, `@` followed by whitespace, or a body made only of trimmed punctuation is not a token. A body starting with another `@` (`@@x`) is not a token.
  • `@session:<id>` fills SessionID; `@session:` with an empty id (after trimming) is not a token. Every other token fills Path.

Start and End are UTF-16 code-unit offsets into text, matching the offset model the web composer and internal/command use.

func ParseCounted

func ParseCounted(text string) ([]Token, int)

ParseCounted is Parse plus the number of candidate tokens past MaxCandidateTokens that were left as plain text without being returned.

Only the first MaxCandidateTokens tokens are stored; later candidates are scanned and counted without retaining them, so memory stays bounded however many `@` tokens text carries.

Jump to

Keyboard shortcuts

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