agentctx

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvID      = "AIMS_AGENT_ID"
	EnvName    = "AIMS_AGENT_NAME"
	EnvTool    = "AIMS_AGENT_TOOL"
	EnvCwd     = "AIMS_AGENT_CWD"
	EnvRoute   = "AIMS_AGENT_ROUTE"
	EnvPending = "AIMS_AGENT_PENDING"
	EnvDepth   = "AIMS_CONTEXT_DEPTH"
)

Environment variable names — these MUST match the ones the bring() shell function exports (cmd/bring/shell/templates/*.tmpl). Reading them here is the only way client code learns the current context.

View Source
const (
	TagContext = "this agent's host"
	TagNearby  = "agent subnet (nearby)"
)

Relevance group tags, shared so every completer labels the promoted groups identically. Normal has no tag — the completer keeps its own intrinsic group (locality, category, …) for those.

Variables

This section is empty.

Functions

func CurrentHost

func CurrentHost(con *client.Client) (*hostpb.Host, bool)

CurrentHost resolves the loaded agent to the host it runs on — the anchor for context-aware completion — and returns false when no context is loaded or it can't be resolved. It reads the agent (for its Host id) then the full host (with addresses/ports/trace), both over the teamclient RPC, never the DB directly. Best-effort: any error yields (nil, false) so callers degrade to the context-free path. The client must already be connected (call con.ConnectComplete first).

func PromotedOrder

func PromotedOrder(intrinsic ...string) []string

PromotedOrder prepends the relevance group tags, in their canonical order, to a completer's own intrinsic group order — so the agent's host and its subnet always render first, and every context-aware completer presents the same spatial convention.

func SubnetOf

func SubnetOf(ip net.IP) (string, bool)

SubnetOf returns the address's subnet in CIDR form under the same netmask-free heuristic sameSubnet uses — a /24 for IPv4, a /64 for IPv6 — and false for a nil/unusable address. It is the companion to sameSubnet for callers that need the prefix itself (e.g. offering subnets as scan targets).

Types

type Context

type Context struct {
	ID      string
	Name    string
	Tool    string
	Cwd     string
	Route   string
	Pending string
	Depth   int
}

Context is the loaded agent context, a cheap snapshot read straight from the environment that `aims bring` populated — no server round-trip. ID is the only field guaranteed present; the rest are the display snapshot bring emits.

func Current

func Current() (Context, bool)

Current returns the loaded agent context from the environment, and false when none is loaded (no AIMS_AGENT_ID). Pure and allocation-cheap: safe to call on every completion keystroke.

type Relevance

type Relevance int

Relevance ranks a completion candidate by its relationship to the loaded agent context. Higher is closer.

const (
	Normal    Relevance = iota // no special relationship to the loaded agent
	Nearby                     // on the agent host's subnet
	AgentHost                  // the agent host itself (or an entity attached to it)
)

func RelevanceOfHost

func RelevanceOfHost(h, agentHost *hostpb.Host) Relevance

RelevanceOfHost classifies a host relative to the loaded agent host: Context if it IS the agent host, Nearby if it shares a subnet, else Normal. A nil agentHost (no context loaded) is always Normal, so callers get the context-free behaviour for free.

func RelevanceOfHostID

func RelevanceOfHostID(hostID string, agentHost *hostpb.Host) Relevance

RelevanceOfHostID classifies an entity that references a host only by id — a credential's HostId, a service's host — as Context when that is the agent host, else Normal. Subnet proximity needs addresses, which a bare id lacks, so Nearby is never returned here.

func (Relevance) Tag

func (r Relevance) Tag() string

Tag is the group tag for a relevance, or "" for Normal (the caller then uses its own intrinsic group for that candidate).

Jump to

Keyboard shortcuts

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