resource

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package resource implements @-prefixed resource discovery and inline resolution. When a user types "@path/to/file" or "@sess:id" in a prompt, the reference is resolved to its content before the LLM sees it.

Resolvers are composable — add a new resolver by implementing the Resolver interface and registering it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReplaceRefs

func ReplaceRefs(text string, resolved map[string]string) string

ReplaceRefs replaces all @references in text with inline content blocks. The resolved map is keyed by the full @reference string (e.g. "@src/main.go"). Unresolved references are left as-is.

Types

type FileResolver

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

FileResolver resolves @path/to/file references by glob-matching against a root directory.

func NewFileResolver

func NewFileResolver(root string) *FileResolver

NewFileResolver creates a file resolver rooted at the given directory.

func (*FileResolver) Load

func (f *FileResolver) Load(ctx context.Context, id string) (string, error)

func (*FileResolver) Prefix

func (f *FileResolver) Prefix() string

func (*FileResolver) Search

func (f *FileResolver) Search(ctx context.Context, query string, limit int) ([]Resource, error)

type Ref

type Ref struct {
	Start int    // Byte offset of "@"
	End   int    // Byte offset after the last character of the reference
	Raw   string // Full matched string including "@"
	Path  string // Content after "@" (e.g. "src/main.go")
}

Ref represents a single @reference found in text.

func ParseRefs

func ParseRefs(text string) []Ref

ParseRefs extracts all @references from text. A reference starts with @ and continues until whitespace, end-of-string, or a closing bracket/paren.

type Registry

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

Registry holds all available resource resolvers.

func NewRegistry

func NewRegistry(resolvers ...Resolver) *Registry

NewRegistry creates a resource registry with the given resolvers.

func (*Registry) Load

func (r *Registry) Load(ctx context.Context, ref string) (string, error)

Load resolves a full @reference (e.g. "@src/main.go" or "@sess:abc123") to its content by routing to the correct resolver.

func (*Registry) Search

func (r *Registry) Search(ctx context.Context, query string, limit int) ([]Resource, error)

Search queries all resolvers and merges results.

type Resolver

type Resolver interface {
	// Prefix is the resource prefix (e.g. "sess:" for @sess:...).
	// Empty string means the resolver handles bare @references (like files).
	Prefix() string
	// Search finds resources matching the query. Called for autocomplete.
	Search(ctx context.Context, query string, limit int) ([]Resource, error)
	// Load retrieves the full content of a resource by its full ID (e.g. "@src/main.go").
	Load(ctx context.Context, id string) (string, error)
}

A Resolver discovers and loads resources by type.

type Resource

type Resource struct {
	ID      string `json:"id"`     // Full @ reference (e.g. "@src/main.go")
	Type    string `json:"type"`   // "file", "session", "skill"
	Label   string `json:"label"`  // Display label (e.g. "src/main.go")
	Detail  string `json:"detail"` // One-line description (e.g. "Go source, 142 lines")
	Content string `json:"-"`      // Full content (not sent in search results)
}

Resource is a discovered resource returned by a Resolver.

type SessionResolver

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

SessionResolver resolves @sess:id references from a session store.

func NewSessionResolver

func NewSessionResolver(sessionDir string) *SessionResolver

NewSessionResolver creates a session resolver.

func (*SessionResolver) Load

func (s *SessionResolver) Load(ctx context.Context, id string) (string, error)

func (*SessionResolver) Prefix

func (s *SessionResolver) Prefix() string

func (*SessionResolver) Search

func (s *SessionResolver) Search(ctx context.Context, query string, limit int) ([]Resource, error)

Jump to

Keyboard shortcuts

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