cliagent

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 24 Imported by: 1 module, 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 cliagent turns an explicit, reviewed description of an existing command-line tool into coding-agent host plugins (Codex, Claude Code and Cursor) and serves that description as a stdio MCP server.

The package does not infer capabilities. A Spec names one canonical executable, a version probe, and a finite list of tools. Each tool is a fixed argv prefix followed by named, typed inputs rendered as flags or positional arguments. Anything the specification does not declare cannot be invoked: there is no shell, no generic command tool and no executable chosen by tool arguments.

Render produces deterministic plugin files, Generate writes them to an absent or empty directory without overwriting, and Check detects drift read-only. NewRunner resolves and probes the installed CLI, and NewServer exposes the declared tools through the official MCP Go SDK.

Tool annotations and input schemas describe declared effects; they are not authorization, sandboxing or approval. The CLI runs with the caller's environment and the same trust as invoking it directly, and its output may contain anything the CLI prints, including secrets. See docs/cli-agent-plugins.md for the contract, limits and evidence.

Index

Constants

View Source
const (
	HostCodex      = "codex"
	HostClaudeCode = "claude-code"
	HostCursor     = "cursor"
)

Hosts rendered by Render, in output order.

View Source
const (
	MaxSpecBytes = 256 << 10
	// MaxInlineSpecBytes leaves headroom below Linux's 128 KiB per-argument
	// exec limit. Validate measures canonical JSON, including escaping.
	MaxInlineSpecBytes = 96 << 10
	MaxTimeoutSeconds  = 600
	MaxOutputBytes     = 1 << 20
	MaxConcurrent      = 16
	MaxTools           = 64
	MaxInputsPerTool   = 32
	MaxArgvPrefix      = 16
	MaxArgLength       = 256
	MaxStringInput     = 64 << 10
	DefaultStringInput = 4096
	MaxEnumValues      = 64
	MaxInstructions    = 64 << 10
)

Bounds enforced by Spec.Validate. They are deliberately small: a spec is reviewed by a person and embedded inline in host MCP configuration.

View Source
const (
	TypeString  = "string"
	TypeBoolean = "boolean"
	TypeInteger = "integer"
)

Input types.

View Source
const (
	CostNone     = "none"
	CostPossible = "possible"
)

Cost values.

View Source
const CodexMarketplacePath = ".agents/plugins/marketplace.json"

CodexMarketplacePath is the local Codex marketplace catalog, relative to the output root. Its single entry points at the codex host folder, so the output root is a marketplace source for `codex plugin marketplace add`.

View Source
const DefaultKillGrace = 5 * time.Second

DefaultKillGrace is how long a canceled or timed-out process group has after SIGTERM before SIGKILL.

View Source
const SchemaVersion = 1

SchemaVersion is the only accepted Spec.SchemaVersion.

View Source
const ServerCommand = "amsl-agent-plugin"

ServerCommand is the executable host MCP configuration starts. It must be installed on PATH alongside the described CLI.

Variables

View Source
var ErrBusy = errors.New("cliagent: concurrency limit reached; call rejected")

ErrBusy reports that MaxConcurrent invocations are already running.

View Source
var ErrDrift = errors.New("cliagent: generated output drift")

ErrDrift reports that generated output differs from the spec's rendering.

View Source
var ErrIncompatibleCLI = errors.New("cliagent: CLI missing or incompatible")

ErrIncompatibleCLI reports a missing executable or failed version probe.

View Source
var ErrInvalidArguments = errors.New("cliagent: invalid arguments")

ErrInvalidArguments wraps every tool-argument validation failure.

View Source
var ErrInvalidSpec = errors.New("cliagent: invalid spec")

ErrInvalidSpec wraps every specification validation failure.

View Source
var ErrOutputExists = errors.New("cliagent: output directory must be absent or empty")

ErrOutputExists reports that the output directory is not absent or empty.

View Source
var ErrUnknownTool = errors.New("cliagent: unknown tool")

ErrUnknownTool reports a tool name the spec does not declare.

Hosts lists every rendered host directory.

Functions

func Check

func Check(s *Spec, outDir string) error

Check compares outDir with the rendering of s without modifying anything. It reports missing, changed and unexpected files, symlinks and non-regular entries, and returns an error wrapping ErrDrift listing every problem.

func Generate

func Generate(s *Spec, outDir string) error

Generate renders s into outDir. outDir must be absent or an empty real directory other than the process working directory; nothing existing is overwritten or deleted. Files are staged in a sibling temporary directory and moved into place with a single rename, so a failure leaves no partial output and a concurrent writer cannot be clobbered. An existing empty outDir is removed with rmdir (which fails if it gained content) immediately before the rename; rename never replaces a non-empty directory.

func NewServer

func NewServer(r *Runner) *mcp.Server

NewServer returns an MCP server advertising exactly the tools declared in the runner's spec. Argument errors, busy rejections and process failures are tool results with IsError set, so the calling model sees them.

func Paths

func Paths(s *Spec) ([]string, error)

Paths returns the slash-separated relative paths Generate writes, sorted.

Types

type Author

type Author struct {
	Name string `json:"name"`
	URL  string `json:"url,omitempty"`
}

Author identifies the plugin author.

type CLI

type CLI struct {
	// Executable is a bare command name resolved once through PATH at startup.
	Executable string `json:"executable"`
	// Install is human setup guidance rendered into README files.
	Install      string       `json:"install"`
	VersionProbe VersionProbe `json:"version_probe"`
}

CLI names the canonical executable and how compatibility is checked.

type Effects

type Effects struct {
	ReadOnly    bool   `json:"read_only"`
	Destructive bool   `json:"destructive"`
	Idempotent  bool   `json:"idempotent"`
	Network     bool   `json:"network"`
	Cost        string `json:"cost"`
	Notes       string `json:"notes"`
}

Effects declares what a tool may do. They become MCP annotations and README text; they are hints for hosts and people, never enforcement.

type File

type File struct {
	Path string
	Data []byte
}

File is one rendered artifact. Path is slash-separated and relative to the output directory.

func Render

func Render(s *Spec) ([]File, error)

Render returns every generated file for all hosts, sorted by path. Output is a pure function of the validated spec: no clock, environment, or local paths.

type Input

type Input struct {
	Name        string   `json:"name"`
	Type        string   `json:"type"`
	Description string   `json:"description"`
	Flag        string   `json:"flag,omitempty"`
	Positional  bool     `json:"positional,omitempty"`
	Required    bool     `json:"required,omitempty"`
	Enum        []string `json:"enum,omitempty"`
	MaxLength   int      `json:"max_length,omitempty"`
	Minimum     *int64   `json:"minimum,omitempty"`
	Maximum     *int64   `json:"maximum,omitempty"`
}

Input is one named argument. Exactly one of Flag or Positional is set.

type Limits

type Limits struct {
	TimeoutSeconds int `json:"timeout_seconds"`
	// MaxOutputBytes is shared by stdout and stderr of one invocation.
	MaxOutputBytes int `json:"max_output_bytes"`
	// MaxConcurrent bounds simultaneous invocations; excess calls are rejected.
	MaxConcurrent int `json:"max_concurrent"`
}

Limits bound every tool invocation.

type Plugin

type Plugin struct {
	Name        string   `json:"name"`
	DisplayName string   `json:"display_name,omitempty"`
	Version     string   `json:"version"`
	Description string   `json:"description"`
	Author      Author   `json:"author"`
	Homepage    string   `json:"homepage,omitempty"`
	Repository  string   `json:"repository,omitempty"`
	License     string   `json:"license,omitempty"`
	Keywords    []string `json:"keywords,omitempty"`
}

Plugin is host-facing package metadata.

type Result

type Result struct {
	Argv      []string `json:"argv"`
	ExitCode  int      `json:"exit_code"`
	Stdout    string   `json:"stdout"`
	Stderr    string   `json:"stderr"`
	Truncated bool     `json:"truncated"`
	TimedOut  bool     `json:"timed_out"`
	Canceled  bool     `json:"canceled"`
	// WaitError reports incomplete output collection or another wait failure.
	WaitError string `json:"wait_error,omitempty"`
}

Result is the structured outcome of one invocation. It never contains usage or cost figures: the runner does not know them.

func (Result) Failed

func (r Result) Failed() bool

Failed reports whether the invocation did not complete successfully.

type Runner

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

Runner invokes declared tools of one resolved executable.

func NewRunner

func NewRunner(ctx context.Context, s *Spec, opts RunnerOptions) (*Runner, error)

NewRunner validates s, resolves its executable once through PATH to an absolute path, and runs the version probe. It returns ErrIncompatibleCLI (with the probe output) when the CLI is absent or the probe fails; there is no fallback executable.

func (*Runner) Call

func (r *Runner) Call(ctx context.Context, tool string, args json.RawMessage) (Result, error)

Call validates arguments and runs the named tool. Validation, busy and unknown-tool failures return an error before any process starts; process outcomes (including non-zero exit, timeout and cancellation) are reported in Result.

func (*Runner) Executable

func (r *Runner) Executable() string

Executable returns the absolute path resolved at startup.

func (*Runner) Workspace

func (r *Runner) Workspace() string

Workspace returns the child working directory.

type RunnerOptions

type RunnerOptions struct {
	// Workspace is the child working directory. Empty means the current
	// working directory at startup.
	Workspace string
	// KillGrace overrides DefaultKillGrace when positive.
	KillGrace time.Duration
	// LookPath overrides exec.LookPath (tests only need this to avoid
	// mutating PATH).
	LookPath func(string) (string, error)
}

RunnerOptions configure NewRunner.

type Skill

type Skill struct {
	Name         string `json:"name"`
	Description  string `json:"description"`
	Instructions string `json:"instructions"`
}

Skill is the user-invoked workflow rendered identically for every host.

type Spec

type Spec struct {
	SchemaVersion int     `json:"schema_version"`
	Plugin        Plugin  `json:"plugin"`
	CLI           CLI     `json:"cli"`
	Skill         Skill   `json:"skill"`
	Limits        Limits  `json:"limits"`
	Tools         []*Tool `json:"tools"`
}

Spec is the reviewed, declarative description of one CLI. It contains no secrets and is bundled verbatim (in canonical form) with generated plugins.

func LoadSpec

func LoadSpec(path string) (*Spec, error)

LoadSpec reads a regular spec file (symlinks rejected) and parses it.

func ParseSpec

func ParseSpec(data []byte) (*Spec, error)

ParseSpec strictly decodes and validates a spec. Unknown fields, duplicate object keys, trailing values and oversize input are rejected.

func (*Spec) Canonical

func (s *Spec) Canonical() ([]byte, error)

Canonical returns the deterministic compact JSON form of the spec used for inline MCP startup, bundling and digests.

func (*Spec) Tool

func (s *Spec) Tool(name string) *Tool

Tool returns the named tool or nil.

func (*Spec) Validate

func (s *Spec) Validate() error

Validate checks every field. It is called by ParseSpec; callers that build a Spec in code must call it before Render, Generate or NewRunner.

type Tool

type Tool struct {
	Name           string   `json:"name"`
	Title          string   `json:"title,omitempty"`
	Description    string   `json:"description"`
	Argv           []string `json:"argv"`
	Inputs         []*Input `json:"inputs,omitempty"`
	Effects        Effects  `json:"effects"`
	TimeoutSeconds int      `json:"timeout_seconds,omitempty"`
}

Tool is one fixed CLI command exposed as an MCP tool.

func (*Tool) BuildArgv

func (t *Tool) BuildArgv(raw json.RawMessage) ([]string, error)

BuildArgv validates raw MCP tool arguments against the tool's declared inputs and returns the argv that follows the executable: the fixed prefix, then inputs in declaration order. Each value is exactly one argv element; no shell parsing or splitting happens anywhere.

func (*Tool) InputSchema

func (t *Tool) InputSchema() map[string]any

InputSchema returns the JSON Schema object advertised for the tool. additionalProperties is false; the server re-validates every call itself.

type VersionProbe

type VersionProbe struct {
	Argv          []string `json:"argv"`
	RequireOutput string   `json:"require_output"`
}

VersionProbe runs Executable with Argv before serving. The probe passes only when the process exits 0 and its combined output contains RequireOutput.

Jump to

Keyboard shortcuts

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