Help us shape the future of Go! Take the 2026 Go Developer Survey

resources

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: Apache-2.0 Imports: 44 Imported by: 1

Documentation

Index

Constants

View Source
const Name = "resources"

Name identifies the resources tool service namespace

Variables

This section is empty.

Functions

func WithAgentFinder

func WithAgentFinder(f agmodel.Finder) func(*Service)

WithAgentFinder attaches an agent finder to resolve agent resources in context.

func WithConversationClient

func WithConversationClient(c apiconv.Client) func(*Service)

WithConversationClient attaches a conversation client for context-aware filtering.

func WithDefaultEmbedder

func WithDefaultEmbedder(id string) func(*Service)

WithDefaultEmbedder specifies a default embedder ID to use when the caller does not provide one. This typically comes from executor config defaults.

func WithDefaults

func WithDefaults(d ResourcesDefaults) func(*Service)

WithDefaults configures default roots and presentation hints.

func WithMCPManager

func WithMCPManager(m *mcpmgr.Manager) func(*Service)

WithMCPManager attaches an MCP manager for listing/downloading MCP

func WithSkillService added in v0.1.8

func WithSkillService(skillSvc *skillsvc.Service) func(*Service)

Types

type GrepInput

type GrepInput struct {
	// Pattern is a required search expression. Internally it may be split on
	// simple OR separators ("|" or " or ") into multiple patterns which are
	// combined using logical OR.
	Pattern string `json:"pattern" description:"search pattern; supports OR via '|' or textual 'or' (case-insensitive)"`
	// ExcludePattern optionally defines patterns that, when matched, cause a
	// file or snippet to be excluded. It follows the same splitting rules as
	// Pattern.
	ExcludePattern string `json:"excludePattern,omitempty" description:"exclude pattern; same OR semantics as pattern"`

	// RootURI is the normalized or user-provided root URI. Prefer using
	// RootID when possible; RootURI is retained for backward compatibility.
	RootURI string `json:"root,omitempty"`
	// RootID is a stable identifier corresponding to a root returned by
	// roots. When provided, it is resolved to the underlying
	// normalized URI before enforcement and grep operations.
	RootID    string   `json:"rootId,omitempty"`
	Path      string   `json:"path"`
	Recursive bool     `json:"recursive,omitempty"`
	Include   []string `` /* 143-byte string literal not displayed */
	Exclude   []string `json:"exclude,omitempty" description:"optional file/path globs to exclude; supports ** for any depth"`

	CaseInsensitive bool `json:"caseInsensitive,omitempty"`

	Mode      string `` /* 159-byte string literal not displayed */
	Bytes     int    `json:"bytes,omitempty"`
	Lines     int    `json:"lines,omitempty"`
	MaxFiles  int    `json:"maxFiles,omitempty"`
	MaxBlocks int    `json:"maxBlocks,omitempty"`

	SkipBinary  bool `json:"skipBinary,omitempty"`
	MaxSize     int  `json:"maxSize,omitempty"`
	Concurrency int  `json:"concurrency,omitempty"`
}

type GrepOutput

type GrepOutput struct {
	Stats textutil.GrepStats  `json:"stats"`
	Files []textutil.GrepFile `json:"files,omitempty"`
}

type ListInput

type ListInput struct {
	// RootURI is the normalized or user-provided root URI. Prefer using
	// RootID when possible; RootURI is retained for backward compatibility
	// but hidden from public schemas.
	RootURI string `json:"root,omitempty" internal:"true" description:"normalized or user-provided root URI; prefer rootId when available"`
	// RootID is a stable identifier corresponding to a root returned by
	// roots. When provided, it is resolved to the underlying
	// normalized URI before enforcement and listing.
	RootID string `json:"rootId,omitempty" description:"resource root id returned by roots"`
	// Path is an optional subpath under the selected root. When empty, the
	// root itself is listed. Paths may be relative to the root or
	// absolute-like; absolute-like paths must remain under the root.
	Path string `json:"path,omitempty" description:"optional subpath under the root to list"`
	// Recursive controls whether the listing should walk the subtree under
	// Path. When false, only immediate children are returned.
	Recursive bool `json:"recursive,omitempty" description:"when true, walk recursively under path"`
	// Include defines optional file or path globs to include. When provided,
	// only items whose relative path or base name matches at least one
	// pattern are returned. Globs use path-style matching rules and support
	// globstar ("**") to match any directory depth.
	Include []string `json:"include,omitempty" description:"optional file/path globs to include (relative to root+path); supports ** for any depth"`
	// Exclude defines optional file or path globs to exclude. When provided,
	// any item whose relative path or base name matches a pattern is
	// filtered out.
	Exclude []string `json:"exclude,omitempty" description:"optional file/path globs to exclude; supports ** for any depth"`
	// MaxItems caps the number of items returned. When zero or negative, no
	// explicit limit is applied.
	MaxItems int `json:"maxItems,omitempty" description:"maximum number of items to return; 0 means no limit"`
}

type ListItem

type ListItem struct {
	URI      string    `json:"uri"`
	Path     string    `json:"path"`
	Name     string    `json:"name"`
	Size     int64     `json:"size"`
	Modified time.Time `json:"modified"`
	RootID   string    `json:"rootId,omitempty"`
}

type ListOutput

type ListOutput struct {
	Items []ListItem `json:"items"`
	Total int        `json:"total"`
}

type MatchDocumentsInput

type MatchDocumentsInput struct {
	Query        string          `json:"query" description:"semantic search query" required:"true"`
	RootIDs      []string        `json:"rootIds,omitempty" description:"resource root ids returned by roots"`
	Path         string          `json:"path,omitempty" description:"optional subpath relative to selected roots"`
	Model        string          `json:"model,omitempty" internal:"true"`
	MaxDocuments int             `json:"maxDocuments,omitempty" description:"maximum number of matched documents (distinct URIs); defaults to 5"`
	Match        *embopt.Options `json:"match,omitempty" internal:"true"`
	Exclude      []string        `json:"exclude,omitempty" description:"optional file/path globs to exclude from match results; supports ** for any depth"`
}

type MatchDocumentsOutput

type MatchDocumentsOutput struct {
	Documents []MatchedDocument `json:"documents"`
}

type MatchInput

type MatchInput struct {
	Query string `json:"query"`
	// RootURI/Roots are retained for backward compatibility but will default to all accessible roots when omitted.
	RootURI []string `json:"rootUri,omitempty" internal:"true"`
	Roots   []string `json:"roots,omitempty" internal:"true"`
	// RootIDs contains stable identifiers corresponding to roots returned by
	// roots. When provided, they are resolved to URIs before
	// enforcement and search.
	RootIDs      []string        `json:"rootIds,omitempty" description:"resource root ids returned by roots"`
	Path         string          `json:"path,omitempty"`
	Model        string          `json:"model" internal:"true"`
	MaxDocuments int             `json:"maxDocuments,omitempty" `
	IncludeFile  bool            `json:"includeFile,omitempty" internal:"true"`
	Match        *embopt.Options `json:"match,omitempty"`
	Exclude      []string        `json:"exclude,omitempty" description:"optional file/path globs to exclude from match results; supports ** for any depth"`
	// LimitBytes controls the maximum total bytes of matched content returned for the current cursor page.
	LimitBytes int `json:"limitBytes,omitempty" description:"Max total bytes per page of matched content. Default: 7000."`
	// Cursor selects the page (1..N) over the ranked documents, grouped by LimitBytes.
	Cursor int `json:"cursor,omitempty" description:"Result page selector (1..N). Default: 1."`
}

MatchInput defines parameters for semantic search across one or more roots.

type MatchOutput

type MatchOutput struct {
	aug.AugmentDocsOutput
	// NextCursor points to the next page (cursor+1) when more content is available; 0 means no further pages.
	NextCursor int `json:"nextCursor,omitempty" description:"Next page cursor when available; 0 when none."`
	// Cursor echoes the selected page.
	Cursor int `json:"cursor,omitempty" description:"Selected page cursor (1..N)."`
	// LimitBytes echoes the applied byte limit per page.
	LimitBytes int `json:"limitBytes,omitempty" description:"Applied byte cap per page."`
	// SystemContent mirrors Content but only includes system-role documents so callers can surface
	// protected context as system messages.
	SystemContent string `json:"systemContent,omitempty" description:"Formatted content for system resources only."`
	// DocumentRoots maps document SourceURI values to their originating root IDs.
	DocumentRoots map[string]string `json:"documentRoots,omitempty" description:"Maps document source URIs to their root IDs."`
}

MatchOutput mirrors augmenter.AugmentDocsOutput for convenience.

type MatchedDocument

type MatchedDocument struct {
	URI    string  `json:"uri"`
	RootID string  `json:"rootId,omitempty"`
	Score  float32 `json:"score"`
}

type ReadImageInput

type ReadImageInput struct {
	// URI is an absolute URI; when provided, RootURI/RootID/Path are ignored.
	URI string `json:"uri,omitempty"`
	// RootURI/RootID + Path select an image under a root.
	RootURI string `json:"root,omitempty"`
	RootID  string `json:"rootId,omitempty"`
	Path    string `json:"path,omitempty"`

	// MaxWidth/MaxHeight define a resize-to-fit box; default 2048x768.
	MaxWidth  int `json:"maxWidth,omitempty"`
	MaxHeight int `json:"maxHeight,omitempty"`
	// MaxBytes caps the encoded output bytes; default 4MB.
	MaxBytes int `json:"maxBytes,omitempty"`

	// Format optionally forces output encoding: "png" or "jpeg".
	Format string `json:"format,omitempty"`

	// IncludeData controls whether dataBase64 is returned in the tool response.
	// When false (default), the tool writes the encoded image to EncodedURI and
	// omits dataBase64 to keep tool output small.
	IncludeData bool `json:"includeData,omitempty"`
	// DestURL optionally specifies where to write the encoded image (file://...).
	DestURL string `json:"destURL,omitempty"`
}

type ReadImageOutput

type ReadImageOutput struct {
	URI      string `json:"uri"`
	Encoded  string `json:"encodedURI,omitempty"`
	Path     string `json:"path"`
	Name     string `json:"name,omitempty"`
	MimeType string `json:"mimeType"`
	Width    int    `json:"width"`
	Height   int    `json:"height"`
	Bytes    int    `json:"bytes"`
	Base64   string `json:"dataBase64,omitempty"`
}

type ReadInput

type ReadInput struct {
	// RootURI is the normalized or user-provided root URI. Prefer using
	// RootID when possible; RootURI is retained for backward compatibility
	// but hidden from public schemas.
	RootURI string `json:"root,omitempty" internal:"true"`
	// RootID is a stable identifier corresponding to a root returned by
	// roots. When provided (and URI is empty), it is resolved to
	// the underlying normalized URI before enforcement and reading.
	RootID string `json:"rootId,omitempty"`
	Path   string `json:"path,omitempty"`
	URI    string `json:"uri,omitempty"`

	// Range selectors; nested objects accepted by JSON schema
	BytesRange textutil.BytesRange `json:"bytesRange,omitempty"`
	textutil.LineRange

	// MaxBytes caps the returned payload when neither byte nor line ranges are provided.
	// When zero, defaults are applied.
	MaxBytes int `json:"maxBytes,omitempty"`

	// Mode provides lightweight previews without full reads:
	// head (default), tail, signatures.
	Mode string `json:"mode,omitempty"`
}

type ReadOutput

type ReadOutput struct {
	URI       string `json:"uri"`
	Path      string `json:"path"`
	Content   string `json:"content"`
	SkillName string `json:"skillName,omitempty"`
	Size      int    `json:"size"`
	// Returned and Remaining describe how much of the original payload was
	// returned after applying caps/ranges.
	Returned  int `json:"returned,omitempty"`
	Remaining int `json:"remaining,omitempty"`
	// StartLine and EndLine are 1-based line numbers describing the selected
	// slice when Offset/Limit were provided. They are zero when the entire
	// (possibly MaxBytes-truncated) file content is returned.
	StartLine int `json:"startLine,omitempty"`
	EndLine   int `json:"endLine,omitempty"`
	// Binary is true when the content was detected as binary and not fully returned.
	Binary bool `json:"binary,omitempty"`
	// ModeApplied echoes the preview mode applied.
	ModeApplied string `json:"modeApplied,omitempty"`
	// Continuation carries paging/truncation hints when content was clipped.
	Continuation *extension.Continuation `json:"continuation,omitempty"`
	// Observation records the full resource hash used by patch tools to enforce read-before-modify.
	Observation *observation.Metadata `json:"observation,omitempty"`
}

ReadOutput contains the resolved URI, relative path and optionally truncated content.

type ResourcesDefaults

type ResourcesDefaults struct {
	Locations    []string
	TrimPath     string
	SummaryFiles []string
	DescribeMCP  bool
	SnapshotPath string
}

type Root

type Root struct {
	// ID is a stable identifier for this root when available. When the
	// underlying agent resource entry defines an explicit id, it is surfaced
	// here. Otherwise, the normalized URI is used as a fallback id so callers
	// can still use rootId as an alias for the URI.
	ID string `json:"id"`

	URI         string `json:"uri"`
	Description string `json:"description,omitempty"`
	// UpstreamRef is an internal-only reference used to resolve local upstream sync.
	UpstreamRef string `json:"-"`
	// DB is an optional embedius sqlite database path override for this root.
	DB string `json:"-"`
	// Match carries per-root match options (include/exclude/max file size).
	Match *embopt.Options `json:"match,omitempty"`
	// AllowedSemanticSearch reports whether semantic match (match)
	// is permitted for this root in the current agent configuration.
	AllowedSemanticSearch bool `json:"allowedSemanticSearch"`
	// AllowedGrepSearch reports whether lexical grep (grepFiles)
	// is permitted for this root in the current agent configuration.
	AllowedGrepSearch bool   `json:"allowedGrepSearch"`
	Role              string `json:"role,omitempty"`
}

type RootsInput

type RootsInput struct {
	MaxRoots int `json:"maxRoots,omitempty"`
}

type RootsOutput

type RootsOutput struct {
	Roots []Root `json:"roots"`
}

type Service

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

Service exposes resource roots, listing, reading and semantic match over filesystem and MCP

func New

func New(augmenter *aug.Service, opts ...func(*Service)) *Service

New returns a resources service using a shared augmenter instance.

func (*Service) CacheableMethods added in v0.1.7

func (s *Service) CacheableMethods() map[string]bool

CacheableMethods declares which methods produce cacheable outputs.

func (*Service) Method

func (s *Service) Method(name string) (svc.Executable, error)

Method resolves an executable method by name

func (*Service) Methods

func (s *Service) Methods() svc.Signatures

Methods declares available tool methods

func (*Service) Name

func (s *Service) Name() string

Name returns service name

func (*Service) ToolTimeout

func (s *Service) ToolTimeout() time.Duration

ToolTimeout suggests a longer timeout for resources tools that may index large roots.

Jump to

Keyboard shortcuts

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