attachbind

package
v1.125.3 Latest Latest
Warning

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

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

Documentation

Overview

Package attachbind binds a prompt's attached material into the serving surfaces: the reference material a prompt attaches (managed resources, #1013) and the automations it references (managed scripts, #1289).

It exists as its own package for the reason the structural gate exists: the prompt layer is at its size ceiling, and material binding is the cohesive piece that comes out whole. What it owns is the boundary between a request and the two resolvers — deriving the caller's identity from the request context, appending each kind's content to a prompts/get result in a fixed order, and running the promotion guard across both kinds — while pkg/prompt/ attachserve keeps the resolution rules themselves.

Every path degrades rather than fails. A resolver that was never bound contributes nothing, which is exactly what a deployment without managed resources or without a database should serve.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Binder

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

Binder holds the bound resolvers. Both are set after construction, because each is assembled later than the prompt layer — the managed-resource layer and the script store both come up after prompts do.

func New

func New() *Binder

New returns an empty binder. A binder with nothing bound is valid and serves every prompt without material, so callers need no nil checks.

func (*Binder) AppendContent

func (b *Binder) AppendContent(ctx context.Context, res *mcp.GetPromptResult, pr *prompt.Prompt, personas []string)

AppendContent adds a prompt's material to a prompts/get result as additional user-role messages: the attached reference material first, then the referenced automations.

They are separate messages rather than extra content on the prompt's own message because a prompt message carries exactly one content item in the MCP schema, and because keeping the procedure and its materials in distinct messages is what lets a client render or elide the materials independently. The order is the authored one: what the procedure reads from comes before what it runs.

func (*Binder) GuardScope

func (b *Binder) GuardScope(ctx context.Context, p *prompt.Prompt) error

GuardScope is the shared store's attachment guard: it refuses a write that would leave one of the prompt's attached materials unreachable for the audience the write gives it.

Two targets are checked, because a prompt can reach a wider audience two ways. The prompt's own scope covers a direct edit and an admin's approval of a promotion (which lands the new scope on the row). A pending promotion request covers the moment an owner asks: the author is the only person who can re-scope or detach the material, so they must be told at request time rather than the reviewer discovering it at approval.

Only attached reference material is checked. A referenced script resolves for its owner alone at every prompt scope, so promoting a prompt cannot widen it past a script's audience; the author is told what a reference serves when they attach it.

It fails closed. A resolver error blocks the write, because the alternative is silently publishing a shared procedure whose material nobody but its author can read.

func (*Binder) ResolveResources

func (b *Binder) ResolveResources(ctx context.Context, pr *prompt.Prompt, personas []string) []attachserve.Resolved

ResolveResources evaluates a prompt's attached materials for the caller identified by the request context. It returns nil when no resolver is bound, when the prompt has no id (static and file prompts cannot carry attachments), or when the prompt has none.

Identity comes from the PlatformContext: the tool-call middleware sets it on manage_prompt use, and the prompt-visibility middleware sets it on prompts/get. Without one the caller is anonymous, which resolves only global materials — the same set an unauthenticated reader already sees.

func (*Binder) ResolveScripts

func (b *Binder) ResolveScripts(ctx context.Context, pr *prompt.Prompt) []attachserve.ResolvedScript

ResolveScripts evaluates a prompt's referenced managed scripts for the same caller, on the same terms: nil without a resolver, without a stored prompt, or when the prompt references none.

A script is its owner's, so the only identity this needs is the caller's address. A request carrying no PlatformContext resolves as nobody, which reaches no script at all.

func (*Binder) Scripts

func (b *Binder) Scripts() *attachserve.ScriptResolver

Scripts returns the bound script resolver, nil when none is bound. The manage_prompt attach/detach commands act through it.

func (*Binder) SetResources

func (b *Binder) SetResources(r *attachserve.Resolver)

SetResources binds the resolver for attached reference material.

func (*Binder) SetScripts

func (b *Binder) SetScripts(r *attachserve.ScriptResolver)

SetScripts binds the resolver for referenced managed scripts.

Jump to

Keyboard shortcuts

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