Documentation
¶
Overview ¶
Package contentlink recognizes activatable references in rendered text.
Recognition is presentation-neutral and side-effect free. Callers provide ready resolver snapshots; unresolved candidates are returned as pending work for a later command rather than resolved during rendering.
Index ¶
- Constants
- func Activatable(k Kind) bool
- func Decorate(line string, spans []Span) string
- func IssueID(value string) bool
- func NoteID(value string) bool
- func SafeHTTPURL(raw string) (string, bool)
- func SessionName(value string) bool
- func StripOSC8(line string) string
- func WrapVisualRange(line string, startCol, endCol int, open, close string) string
- type BeginOutcome
- type DiffResolver
- type Extra
- type FrameOptions
- type FrameResult
- type InternalURI
- type Kind
- type KindSet
- type Options
- type Pending
- type Ref
- type ResolutionIndex
- func (i *ResolutionIndex) Apply(result ResolutionResult) (changed, accepted bool)
- func (i *ResolutionIndex) Begin(root string, candidate Pending) (ResolutionRequest, bool)
- func (i *ResolutionIndex) BeginClassified(root string, candidate Pending) (ResolutionRequest, BeginOutcome)
- func (i *ResolutionIndex) BeginClassifiedFor(root, hostID string, candidate Pending) (ResolutionRequest, BeginOutcome)
- func (i *ResolutionIndex) Put(candidate Pending, ref Ref, found bool) bool
- func (i *ResolutionIndex) PutForHost(root, hostID string, candidate Pending, ref Ref, found bool) bool
- func (i *ResolutionIndex) PutForRoot(root string, candidate Pending, ref Ref, found bool) bool
- func (i *ResolutionIndex) Reset()
- func (i *ResolutionIndex) Snapshot() ResolutionSnapshot
- func (i *ResolutionIndex) SnapshotForHost(root, hostID string) ResolutionSnapshot
- func (i *ResolutionIndex) SnapshotForRoot(root string) ResolutionSnapshot
- type ResolutionRequest
- type ResolutionResult
- type ResolutionSnapshot
- type Resolver
- type ResourceMatcher
- type Span
- type Surface
- type URIOptions
Constants ¶
const ( MaxNewDiffResolves = 16 MaxResourceLocatorChars = 200 MaxResourceMatchesPerLine = 32 MaxAutomaticMatchesPerLine = 64 MaxRenderedRows = 1000 MaxRenderedColumns = 4096 MaxPendingResolutions = 128 MaxInternalURIBytes = 2048 MaxInternalNamespaceBytes = 32 MaxInternalIDRunes = 512 MaxInternalQueryParameters = 16 MaxInternalQueryKeyBytes = 32 MaxInternalQueryValueRunes = 256 MaxExplicitLabelColumns = 4096 // MaxExplicitDestinationBytes bounds a source-supplied OSC-8 URI before // contentlink retains it in a Span or resynthesizes it into rendered output. // The destination is zero-width terminal control data, so the rendered // column limit cannot bound it. MaxExplicitDestinationBytes = 2048 )
const (
MaxResolutionEntries = 2048
)
Variables ¶
This section is empty.
Functions ¶
func Activatable ¶
Activatable reports whether hosts may bind and decorate the kind.
func Decorate ¶
Decorate underlines local references and synthesizes OSC-8 for safe HTTP(S) destinations: built-in URL spans, and resource spans whose locator is itself a browser URL — a claimed GitHub URL must keep its emulator hyperlink so cmd-click remains the escape hatch even after Sidecar reclassifies the span. A resource span claimed by its rendered label carries the destination it was claimed away from in Extra.Destination and keeps the hyperlink through that, for the same reason. Locators that are keys or refs with no destination stay underline-only.
Source OSC must first be removed by StripOSC8 or ScanFrame.
func SafeHTTPURL ¶
SafeHTTPURL trims prose punctuation and accepts only http(s), with a host and no controls.
func SessionName ¶
SessionName reports whether value is a Sidecar-owned attachable tmux session name. Stored notification targets use the same validation as scans.
Types ¶
type BeginOutcome ¶ added in v1.6.0
type BeginOutcome uint8
const ( BeginRejected BeginOutcome = iota BeginRequested BeginReady BeginInFlight )
type Extra ¶
type Extra struct {
Line int
Raw string
Provider string
Matcher string
Namespace string
Destination string
}
Extra preserves the terminal-link scanner's original public shape while callers migrate to Ref. Raw is the token as rendered before ready resolution.
Destination is set only when a renderer-owned URL yield reclassified an explicit hyperlink by its label: Value becomes the locator the provider is invoked with, and the destination the label pointed at is kept here so decoration can still synthesize the emulator hyperlink. Without it, taking a link over would silently remove the browser escape hatch the label had.
type FrameOptions ¶
type FrameOptions struct {
Ready ResolutionSnapshot
Matchers []ResourceMatcher
InternalNamespaces map[string]URIOptions
// AllowedKinds bounds the kinds returned, decorated, and queued for
// resolution. Nil preserves the scanner's all-kinds default; a non-nil
// empty set allows none. Explicit OSC labels still claim their cells when
// their destination kind is excluded, so automatic matching cannot turn a
// disallowed explicit destination into a different action.
//
// Claim interaction: URL yield runs before this filter, so a surface that
// allows KindURL but not KindResource would drop claimed URLs entirely —
// inert text where a browser link used to be. Every current scanning
// surface advertises both kinds together (docview.ContentLinkKinds is the
// shared set, pinned by test); a future surface wanting one without the
// other must decide what claimed URLs should do first.
AllowedKinds KindSet
Decorate bool
// RendererOwned declares that this frame was drawn by Sidecar's own Markdown
// renderer rather than written by a foreign program.
//
// The never-rewrite-an-explicit-destination rule (condition 3 of the "Why URL
// yield" block on yieldClaimedURLs) exists because a program writing to a PTY
// can lie about where its label points: it can print "td-1234" over a
// destination of its choosing. internal/markdown is not that adversary — the
// hyperlinks it emits are ones Sidecar chose to emit for the document's own
// Markdown links, so a label there is as trustworthy as the same text would
// be if the author had written it bare.
//
// That is the whole license: on a renderer-owned frame a claiming provider
// may reclassify an explicit hyperlink whose label (or destination) its
// matcher owns. It does not widen which hosts may be claimed, it does not let
// an unclaimed host yield, and it is never a default — terminal scanning
// (internal/terminallink) leaves it false and behaves exactly as before.
//
// Glamour does not strip escape sequences already present in the source, so
// a document that writes its own OSC-8 reaches this path on a genuinely
// renderer-owned frame. That is deliberate and bounded rather than
// overlooked: the widened branch cannot yield anything bare automatic
// matching would not already yield for the same text, with the same
// instance, matcher, and locator — a document naming a key it does not own
// gets a card for that key either way. Callers still gate honestly (see
// markdown.RendersMarkdownAt) so the flag means what it says wherever the
// answer is knowable.
RendererOwned bool
}
type FrameResult ¶
type FrameResult struct {
Output string
Spans []Span
Pending []Pending
// ReadyHits counts file/diff candidates answered by the immutable snapshot,
// including cached negatives. It is diagnostic metadata only.
ReadyHits int
}
func ScanFrame ¶
func ScanFrame(frame string, opts FrameOptions) FrameResult
ScanFrame recognizes a bounded, already-rendered ANSI frame. Explicit OSC-8 spans are extracted first and beat automatic matches. File and diff matching consults only Ready; misses become bounded, deduplicated Pending work.
type InternalURI ¶
InternalURI carries the stable intent reference and handler-owned options. Query is copied and may be safely retained by a handler.
func ParseInternalURI ¶
func ParseInternalURI(raw string) (InternalURI, error)
func ParseInternalURIWith ¶
func ParseInternalURIWith(raw string, opts URIOptions) (InternalURI, error)
type Kind ¶
type Kind string
Kind classifies an activatable reference.
const ( KindURL Kind = "url" KindFile Kind = "file" KindIssue Kind = "issue" KindDiff Kind = "diff" KindResource Kind = "resource" KindInternal Kind = "internal" // KindSession identifies a Sidecar-owned tmux session that a host can // attach. Only names Sidecar itself mints are recognized from text. KindSession Kind = "session" )
type KindSet ¶
type KindSet map[Kind]struct{}
KindSet bounds the reference kinds a rendered surface allows the host to recognize. The zero value allows none.
func NewKindSet ¶
NewKindSet constructs a set containing kinds.
type Options ¶
type Options struct {
Resolve Resolver
ResolveDiff DiffResolver
Matchers []ResourceMatcher
}
Options is the line scanner's contract. It deliberately carries no renderer-owned bit: internal/terminallink aliases this type, so a field here would be one `terminallink.Options{RendererOwned: true}` away from reaching terminal scanning. The bit is a parameter of the frame scanner instead, which only ScanFrame can supply.
type Pending ¶
Pending names side-effecting work a caller may run after rendering. Only file and diff candidates are produced. Raw is the exact rendered token.
type Ref ¶
Ref is the presentation-neutral identity produced by every recognition path. Line is 1-based and zero when absent. Provider and Matcher identify an external resource matcher. Namespace is set only for internal intents.
type ResolutionIndex ¶
type ResolutionIndex struct {
// contains filtered or unexported fields
}
ResolutionIndex is a bounded root-aware true LRU. Resolution work happens outside this type; Begin deduplicates work, Apply rejects stale tokens, and snapshots give presentation a ready-only immutable copy. Put and Snapshot retain the rootless document/deck contract.
func NewResolutionIndex ¶
func NewResolutionIndex(limit int) *ResolutionIndex
func NewResolutionIndexWithClock ¶ added in v1.6.0
func NewResolutionIndexWithClock(limit int, now func() time.Time) *ResolutionIndex
func (*ResolutionIndex) Apply ¶ added in v1.6.0
func (i *ResolutionIndex) Apply(result ResolutionResult) (changed, accepted bool)
Apply accepts only the current token. changed reports whether the effective ready answer changed; accepted distinguishes a refresh from a stale result.
func (*ResolutionIndex) Begin ¶ added in v1.6.0
func (i *ResolutionIndex) Begin(root string, candidate Pending) (ResolutionRequest, bool)
Begin returns one request for a currently unresolved root-aware candidate.
func (*ResolutionIndex) BeginClassified ¶ added in v1.6.0
func (i *ResolutionIndex) BeginClassified(root string, candidate Pending) (ResolutionRequest, BeginOutcome)
BeginClassified distinguishes a ready cache answer from work already in flight. Callers use that distinction for truthful cache-hit diagnostics without weakening request deduplication.
func (*ResolutionIndex) BeginClassifiedFor ¶ added in v1.12.0
func (i *ResolutionIndex) BeginClassifiedFor(root, hostID string, candidate Pending) (ResolutionRequest, BeginOutcome)
func (*ResolutionIndex) Put ¶
func (i *ResolutionIndex) Put(candidate Pending, ref Ref, found bool) bool
func (*ResolutionIndex) PutForHost ¶ added in v1.12.0
func (*ResolutionIndex) PutForRoot ¶ added in v1.6.0
func (*ResolutionIndex) Reset ¶
func (i *ResolutionIndex) Reset()
func (*ResolutionIndex) Snapshot ¶
func (i *ResolutionIndex) Snapshot() ResolutionSnapshot
func (*ResolutionIndex) SnapshotForHost ¶ added in v1.12.0
func (i *ResolutionIndex) SnapshotForHost(root, hostID string) ResolutionSnapshot
func (*ResolutionIndex) SnapshotForRoot ¶ added in v1.6.0
func (i *ResolutionIndex) SnapshotForRoot(root string) ResolutionSnapshot
type ResolutionRequest ¶ added in v1.6.0
ResolutionRequest is the root-aware identity carried through asynchronous resolution. Token is never reused and lets Apply reject stale results. HostID is empty on this machine; equal roots on two hosts do not share an answer.
type ResolutionResult ¶ added in v1.6.0
type ResolutionResult struct {
Request ResolutionRequest
Ref Ref
Found bool
}
type ResolutionSnapshot ¶
type ResolutionSnapshot struct {
// contains filtered or unexported fields
}
ResolutionSnapshot is an immutable ready-only view used during rendering. A missing key means unresolved, not a negative result.
func (ResolutionSnapshot) Generation ¶ added in v1.6.0
func (s ResolutionSnapshot) Generation() uint64
type Resolver ¶
Resolver and DiffResolver are the legacy synchronous scanner hooks. New rendered surfaces should use ScanFrame with a ResolutionSnapshot instead.
type ResourceMatcher ¶
ResourceMatcher is one live external matcher. The whole match is the locator.
ClaimHosts carries the matcher's instance configuration: the lowercased hostnames whose built-in URL spans that instance may reclassify into resource spans. It is empty for an instance that claims nothing, and it never widens what Re itself matches — a URL is yielded only when its host is listed here AND Re matches the entire URL string. Built-in precedence is not inverted anywhere else.
type Span ¶
type Span struct {
Kind Kind
Row int
StartCol int
EndCol int
Value string
Extra Extra
Explicit bool
}
Span is one non-overlapping reference in inclusive visual columns. Row is zero for a line scan and the zero-based rendered row for a frame scan.
func ScanWith ¶
ScanWith preserves the existing synchronous terminal scanner contract. Built-ins win in URL, path:line, file, issue, diff, resource order.
func SpanForRef ¶
SpanForRef constructs a coordinate-free span. It is useful at adapters that still consume the compatibility Span vocabulary.
type Surface ¶
type Surface struct {
ID string
Rect mouse.Rect
WorkDir string
ProjectRoot string
Kinds KindSet
ReadOnly bool
// RendererOwned marks a rectangle Sidecar's own Markdown renderer drew, as
// opposed to bytes a foreign program wrote. It licenses exactly one thing —
// see FrameOptions.RendererOwned — and a surface showing anything a PTY, a
// subprocess, or a file's own escape sequences can reach must leave it false.
RendererOwned bool
}
Surface describes one exact, already-rendered text rectangle that a host may scan for content links. Rect uses plugin-local coordinates.
type URIOptions ¶
type URIOptions struct {
AllowedQuery map[string]struct{}
// ValidateID applies namespace-owned identity rules after generic URI
// decoding and bounds checks. A nil validator accepts any generic ID.
ValidateID func(string) bool
}
URIOptions is the generic parser's query allowlist. The zero value accepts no query parameters. Namespace handlers choose their own bounded keys.