core

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package core provides canonical types for AI assistant command/prompt definitions.

Index

Constants

View Source
const DefaultDirMode fs.FileMode = 0700

DefaultDirMode is the default permission for generated directories.

View Source
const DefaultFileMode fs.FileMode = 0600

DefaultFileMode is the default permission for generated files.

Variables

View Source
var DefaultRegistry = NewRegistry()

DefaultRegistry is the global adapter registry.

Functions

func AdapterNames

func AdapterNames() []string

AdapterNames returns adapter names from the default registry.

func Convert

func Convert(data []byte, from, to string) ([]byte, error)

Convert converts using the default registry.

func Register

func Register(adapter Adapter)

Register adds an adapter to the default registry.

func WriteCanonicalFile

func WriteCanonicalFile(cmd *Command, path string) error

WriteCanonicalFile writes a canonical command.json file.

func WriteCommandsToDir

func WriteCommandsToDir(commands []*Command, dir string, adapterName string) error

WriteCommandsToDir writes multiple commands to a directory using the specified adapter.

Types

type Adapter

type Adapter interface {
	// Name returns the adapter identifier (e.g., "claude", "gemini", "codex").
	Name() string

	// FileExtension returns the file extension for this format (e.g., ".md", ".toml").
	FileExtension() string

	// DefaultDir returns the default directory name for commands.
	DefaultDir() string

	// Parse converts tool-specific bytes to canonical Command.
	Parse(data []byte) (*Command, error)

	// Marshal converts canonical Command to tool-specific bytes.
	Marshal(cmd *Command) ([]byte, error)

	// ReadFile reads from path and returns canonical Command.
	ReadFile(path string) (*Command, error)

	// WriteFile writes canonical Command to path.
	WriteFile(cmd *Command, path string) error
}

Adapter converts between canonical Command and tool-specific formats.

func GetAdapter

func GetAdapter(name string) (Adapter, bool)

GetAdapter returns an adapter from the default registry.

type Argument

type Argument struct {
	Name        string `json:"name"`
	Type        string `json:"type"`                  // string, number, boolean
	Required    bool   `json:"required,omitempty"`    // If true, argument is required
	Default     string `json:"default,omitempty"`     // Default value
	Pattern     string `json:"pattern,omitempty"`     // Regex validation pattern
	Hint        string `json:"hint,omitempty"`        // User-facing hint
	Description string `json:"description,omitempty"` // Detailed description
}

Argument represents a command argument.

type Command

type Command struct {
	// Metadata
	Name        string `json:"name"`
	Description string `json:"description"`

	// Arguments
	Arguments []Argument `json:"arguments,omitempty"`

	// Content
	Instructions string `json:"instructions"` // The prompt/instructions content

	// Process steps (for documentation)
	Process []string `json:"process,omitempty"`

	// Dependencies required to run this command
	Dependencies []string `json:"dependencies,omitempty"`

	// Examples of usage
	Examples []Example `json:"examples,omitempty"`
}

Command represents a canonical command/prompt definition that can be converted to tool-specific formats (Claude, Gemini, Codex).

func NewCommand

func NewCommand(name, description string) *Command

NewCommand creates a new Command with the given name and description.

func ReadCanonicalDir

func ReadCanonicalDir(dir string) ([]*Command, error)

ReadCanonicalDir reads all command.json files from a directory.

func ReadCanonicalFile

func ReadCanonicalFile(path string) (*Command, error)

ReadCanonicalFile reads a canonical command.json file.

func (*Command) AddArgument

func (c *Command) AddArgument(arg Argument)

AddArgument adds an argument to the command.

func (*Command) AddDependency

func (c *Command) AddDependency(dep string)

AddDependency adds a dependency to the command.

func (*Command) AddExample

func (c *Command) AddExample(description, input, output string)

AddExample adds a usage example.

func (*Command) AddOptionalArgument

func (c *Command) AddOptionalArgument(name, description, defaultValue string)

AddOptionalArgument adds an optional string argument with a default value.

func (*Command) AddProcessStep

func (c *Command) AddProcessStep(step string)

AddProcessStep adds a step to the process list.

func (*Command) AddRequiredArgument

func (c *Command) AddRequiredArgument(name, description, hint string)

AddRequiredArgument adds a required string argument.

type Example

type Example struct {
	Description string `json:"description,omitempty"`
	Input       string `json:"input"`
	Output      string `json:"output,omitempty"`
}

Example represents a usage example.

type MarshalError

type MarshalError struct {
	Format string
	Err    error
}

MarshalError occurs when marshaling to tool-specific format fails.

func (*MarshalError) Error

func (e *MarshalError) Error() string

func (*MarshalError) Unwrap

func (e *MarshalError) Unwrap() error

type ParseError

type ParseError struct {
	Format string
	Path   string
	Err    error
}

ParseError occurs when parsing tool-specific format fails.

func (*ParseError) Error

func (e *ParseError) Error() string

func (*ParseError) Unwrap

func (e *ParseError) Unwrap() error

type ReadError

type ReadError struct {
	Path string
	Err  error
}

ReadError occurs when reading a file fails.

func (*ReadError) Error

func (e *ReadError) Error() string

func (*ReadError) Unwrap

func (e *ReadError) Unwrap() error

type Registry

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

Registry manages adapter registration and lookup.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new adapter registry.

func (*Registry) AdapterNames

func (r *Registry) AdapterNames() []string

AdapterNames returns all registered adapter names sorted alphabetically.

func (*Registry) Convert

func (r *Registry) Convert(data []byte, from, to string) ([]byte, error)

Convert converts command data from one format to another.

func (*Registry) GetAdapter

func (r *Registry) GetAdapter(name string) (Adapter, bool)

GetAdapter returns an adapter by name.

func (*Registry) Register

func (r *Registry) Register(adapter Adapter)

Register adds an adapter to the registry.

type WriteError

type WriteError struct {
	Path string
	Err  error
}

WriteError occurs when writing a file fails.

func (*WriteError) Error

func (e *WriteError) Error() string

func (*WriteError) Unwrap

func (e *WriteError) Unwrap() error

Jump to

Keyboard shortcuts

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