agentdir

package
v0.4.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package agentdir is experimental: its API and documented formats may change in a minor release; see https://nsgo.games/docs/stability/.

Package agentdir discovers local coding-agent binaries without sending prompts.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeCache

func EncodeCache(c Cache) ([]byte, error)

EncodeCache writes c as YAML with two-space indentation, setting a zero Version to 1 and listing the agents sorted by name, so the same agents always encode to the same bytes. It refuses a cache DecodeCache would refuse.

Example

EncodeCache writes the editor's discovered agents as deterministic version 1 YAML; DecodeCache reads it back and validates every model ID before it reaches an agent's command line.

package main

import (
	"fmt"
	"time"

	"github.com/nsgo-dev/game/pkg/editor/agentdir"
)

func main() {
	cache := agentdir.Cache{Agents: []agentdir.Info{{
		Name:    "codex",
		Path:    "/usr/local/bin/codex",
		Version: "1.2.3",
		SignIn:  agentdir.SignedIn,
		Models:  []agentdir.Model{{ID: "gpt-5", Label: "GPT-5", Effort: []string{"low", "high"}}},
		Checked: time.Date(2026, 11, 28, 9, 0, 0, 0, time.UTC),
	}}}

	data, err := agentdir.EncodeCache(cache)
	if err != nil {
		fmt.Println(err)
		return
	}
	decoded, err := agentdir.DecodeCache(data)
	fmt.Println(err, decoded.Version, len(decoded.Agents), decoded.Agents[0].Name, decoded.Agents[0].Models[0].ID)
}
Output:
<nil> 1 1 codex gpt-5

func ValidateModelID

func ValidateModelID(v string) error

ValidateModelID reports an error unless v is a model ID safe to pass to an agent's command line: 1 to 128 letters, digits and the characters . _ : / @ + -.

Types

type Cache

type Cache struct {
	Version int    `yaml:"version"`
	Agents  []Info `yaml:"agents,omitempty"`
}

Cache is the editor's saved list of discovered agents, a YAML file whose version is 1.

func DecodeCache

func DecodeCache(data []byte) (Cache, error)

DecodeCache reads a cache from YAML, refusing unknown fields, a second document, any version but 1, a sign-in state other than signed_in, signed_out or unknown, and a model ID or effort level ValidateModelID refuses, so a value read back from the file is safe to pass to an agent's command line. Its errors are *loaderr.Error values with the line and field at fault.

type Info

type Info struct {
	Name    string      `yaml:"name"`
	Path    string      `yaml:"path"`
	Version string      `yaml:"version,omitempty"`
	SignIn  SignInState `yaml:"signIn"`
	Models  []Model     `yaml:"models,omitempty"`
	Checked time.Time   `yaml:"checked"`
}

Info describes one agent binary found on this machine: its name, path and version, whether it is signed in, the models it offers and when it was last checked.

func Probe

func Probe(ctx context.Context, name, path string) (Info, error)

Probe runs the binary at path with --version, waiting at most three seconds, and describes it under name with the version it printed and the time it was checked (UTC, whole seconds). It never sends a prompt. A version answer says nothing about signing in, so the sign-in state is always Unknown. A binary that fails returns an Info with an unknown sign-in state and the error.

type Model

type Model struct {
	ID     string   `yaml:"id"`
	Label  string   `yaml:"label,omitempty"`
	Effort []string `yaml:"effort,omitempty"`
}

Model is one model an agent offers: its ID, the label to show and the reasoning-effort levels it accepts.

type SignInState

type SignInState string

SignInState is whether a probed agent's command-line tool is signed in to its provider.

const (
	// SignedIn is an agent whose own protocol answered as signed in.
	SignedIn SignInState = "signed_in"
	// SignedOut is an agent whose own protocol answered with an authentication error.
	SignedOut SignInState = "signed_out"
	// Unknown is an agent no probe has asked about signing in yet.
	Unknown SignInState = "unknown"
)

Jump to

Keyboard shortcuts

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