ops

package
v0.70.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package ops is the operation catalog. A Spec declares one operation once: its name, owner, effect, toolset, typed input, constraints and guidance. The desktop mounts each Spec as an MCP tool, and the hive CLI builds a command from the same Spec, so the two surfaces cannot drift apart.

Index

Constants

View Source
const (
	// DetailSummary omits every source-supplied payload.
	DetailSummary = "summary"
	// DetailFull holds nothing back.
	DetailFull = "full"
)

The two ends of the surface-wide detail ladder.

Every operation whose answer carries source-supplied JSON (an inbox item's payload, an event's detail, a dry run's messages) answers at a size set by data nobody here chose. Rather than a cap that silently truncates, each one takes a detail argument and reports the level it answered at, so an omitted field is never mistaken for an absent one. An operation may add rungs between these; summary and full mean the same thing everywhere.

View Source
const CallerField = "caller"

CallerField is the json name of the input field that says who is calling. The CLI fills it from --caller and gives it no flag of its own.

Variables

View Source
var ErrInvalidCallerRule = fmt.Errorf("not a valid CallerRule, try [%s]", strings.Join(_CallerRuleNames, ", "))
View Source
var SummaryOrFull = Constraint{Enum: []string{DetailSummary, DetailFull}, Default: DetailSummary}

SummaryOrFull is the detail constraint of an operation with no middle rung.

View Source
var Verbs = []string{
	"list", "get", "create", "put", "update", "delete", "clear",
	"open", "close", "move", "focus", "resize", "turn", "preview", "refresh",
}

Verbs is the closed verb vocabulary. put creates or replaces.

Functions

func CallerRuleNames

func CallerRuleNames() []string

CallerRuleNames returns a list of possible string values of CallerRule.

func ExitCode

func ExitCode(k Kind) int

ExitCode is the CLI exit status for a refused call of kind k. An unknown kind exits 1.

Types

type CallerRule

type CallerRule string

CallerRule says which callers an operation with a caller input accepts. A chat caller passes both rules on a desktop-owned operation, because the desktop resolves chats.

ENUM(none, session, session-or-global)

const (
	// CallerRuleNone is a CallerRule of type none.
	CallerRuleNone CallerRule = "none"
	// CallerRuleSession is a CallerRule of type session.
	CallerRuleSession CallerRule = "session"
	// CallerRuleSessionOrGlobal is a CallerRule of type session-or-global.
	CallerRuleSessionOrGlobal CallerRule = "session-or-global"
)

func ParseCallerRule

func ParseCallerRule(name string) (CallerRule, error)

ParseCallerRule attempts to convert a string to a CallerRule.

func (CallerRule) AppendText

func (x CallerRule) AppendText(b []byte) ([]byte, error)

AppendText appends the textual representation of itself to the end of b (allocating a larger slice if necessary) and returns the updated slice.

Implementations must not retain b, nor mutate any bytes within b[:len(b)].

func (CallerRule) IsValid

func (x CallerRule) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (CallerRule) MarshalText

func (x CallerRule) MarshalText() ([]byte, error)

MarshalText implements the text marshaller method.

func (CallerRule) String

func (x CallerRule) String() string

String implements the Stringer interface.

func (*CallerRule) UnmarshalText

func (x *CallerRule) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method.

type Constraint

type Constraint struct {
	Enum     []string
	Min, Max *float64
	// Default is the value an omitted field takes. It is documentation: the
	// handler must treat the zero value the same way.
	Default any
}

Constraint narrows one input field beyond what its Go type says. The MCP schema states it, and the CLI checks it before it calls.

func Range

func Range(lo, hi float64) Constraint

Range is an inclusive numeric bound.

type Constraints

type Constraints map[string]Constraint

Constraints is keyed by json field name.

type Effect

type Effect string

Effect classifies what a call changes.

const (
	EffectRead  Effect = "read"
	EffectWrite Effect = "write"
	// EffectExec runs a command the caller supplies.
	EffectExec Effect = "exec"
)

type Error

type Error struct {
	Kind Kind
	Msg  string
}

Error is an error with a Kind.

func Errorf

func Errorf(kind Kind, format string, args ...any) *Error

func (*Error) Error

func (e *Error) Error() string

type Field

type Field struct {
	Name string
	// Type is the field's Go type with any pointer removed. Pointer says
	// whether there was one: an omitted pointer field keeps a stored value.
	Type        reflect.Type
	Pointer     bool
	Description string
	Required    bool
	Constraint
}

Field is one input field with its constraint applied.

func Fields

func Fields(op Op) ([]Field, error)

Fields lists the input fields of op in declaration order. A Fields key that names no field is an error.

func (Field) Check

func (f Field) Check(v any) error

Check reports whether v satisfies the field's enum and range.

func (Field) Kind

func (f Field) Kind() reflect.Kind

Kind is the kind of Type.

type Info

type Info struct {
	Name     string
	Resource string
	Verb     string
	// ToolName is the MCP tool name: "<resource>_<verb>".
	ToolName string
	Owner    Owner
	Effect   Effect
	Toolset  Toolset
	Summary  string
	Guidance string
	Args     []string
	Fields   Constraints
	Caller   CallerRule
}

Info is a Spec with its type parameter erased.

func (Info) Description

func (i Info) Description() string

Description is the MCP tool description: the summary as a sentence, then the guidance.

type Kind

type Kind string

Kind is the error vocabulary every surface maps once. A tool error crosses MCP as text that starts with "<kind>: ".

const (
	KindInvalid         Kind = "invalid"
	KindNotFound        Kind = "not_found"
	KindConflict        Kind = "conflict"
	KindUnavailable     Kind = "unavailable"
	KindUnauthenticated Kind = "unauthenticated"
	KindInternal        Kind = "internal"
)

func ParseKind

func ParseKind(msg string) (Kind, bool)

ParseKind reads the leading "<kind>:" of a tool error's text.

type NoInput

type NoInput struct{}

NoInput is the input of an operation that takes no arguments.

type Op

type Op interface {
	Info() Info
	InputType() reflect.Type
	// InputSchema is the inferred schema of In with Fields applied. A Fields
	// key that names no input field is an error.
	InputSchema() (*jsonschema.Schema, error)
}

Op is a Spec seen without its type parameter, so a catalog can hold operations of different input types.

type Owner

type Owner string

Owner says where an operation runs.

const (
	// OwnerEngine operations run on hive.Engine.
	OwnerEngine Owner = "engine"
	// OwnerDesktop operations need the running desktop; the CLI reaches them
	// over its MCP servers.
	OwnerDesktop Owner = "desktop"
)

type Spec

type Spec[In any] struct {
	// Name is "<resource>.<verb>". The resource may contain "_", which the
	// CLI spells as "-".
	Name    string
	Owner   Owner
	Effect  Effect
	Toolset Toolset
	// Summary is one line with no final period: the MCP title and the CLI
	// usage.
	Summary string
	// Guidance is the behavior an agent or a person must know: the rest of
	// the MCP description and the CLI long help.
	Guidance string
	// Args are the json names of the fields the CLI takes as positional
	// arguments, in order.
	Args []string
	// Fields adds constraints to input fields, keyed by json name.
	Fields Constraints
	// Caller is the rule for the input's caller field. Leave it unset for an
	// operation with no caller field.
	Caller CallerRule
}

Spec declares one operation with input type In. The output type is not part of the Spec: it belongs to the side that binds the handler.

An In may implement Validator for rules a JSON schema cannot state.

func (Spec[In]) Info

func (s Spec[In]) Info() Info

Info panics on a malformed Name or a verb outside Verbs: both are programming errors that the catalog test catches first.

func (Spec[In]) InputSchema

func (s Spec[In]) InputSchema() (*jsonschema.Schema, error)

func (Spec[In]) InputType

func (Spec[In]) InputType() reflect.Type

type Toolset

type Toolset struct {
	Name    string
	MCPPath string
}

Toolset groups operations. MCPPath is the loopback path of the desktop MCP server that serves them. A toolset is metadata: workspace grants stay per server (ADR a-workspace-declares-its-own-authority).

type Validator

type Validator interface{ Validate() error }

Validator is implemented by an In that has cross-field rules. Mount calls it before the handler, and the CLI calls it before it dials the desktop.

Directories

Path Synopsis
Package actions declares the action catalog, action run and applet operations of the desktop's app-control MCP server.
Package actions declares the action catalog, action run and applet operations of the desktop's app-control MCP server.
Package catalog lists every operation of every toolset.
Package catalog lists every operation of every toolset.
Package diagnostics declares the status and diagnostics operations of the desktop's app-control MCP server.
Package diagnostics declares the status and diagnostics operations of the desktop's app-control MCP server.
Package drive declares the Hive Drive document and canvas operations, served on the drive MCP server.
Package drive declares the Hive Drive document and canvas operations, served on the drive MCP server.
Package flows declares the profile, flow and image operations of the desktop's app-control MCP server.
Package flows declares the profile, flow and image operations of the desktop's app-control MCP server.
Package inbox declares the feed, inbox and source operations of the desktop's app-control MCP server.
Package inbox declares the feed, inbox and source operations of the desktop's app-control MCP server.
Package layout declares the tab, panel and split operations of a chat or Code session, served on the drive MCP server.
Package layout declares the tab, panel and split operations of a chat or Code session, served on the drive MCP server.
Package mcpops mounts catalog operations on an MCP server.
Package mcpops mounts catalog operations on an MCP server.
Package reviews declares the operations an agent uses to review a Code session's branch diff, served on the drive MCP server.
Package reviews declares the operations an agent uses to review a Code session's branch diff, served on the drive MCP server.
Package sessions declares the hive session operations of the desktop's app-control MCP server.
Package sessions declares the hive session operations of the desktop's app-control MCP server.
Package workspaces declares the agent workspace and scheduled chat operations of the desktop's app-control MCP server.
Package workspaces declares the agent workspace and scheduled chat operations of the desktop's app-control MCP server.

Jump to

Keyboard shortcuts

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