aitools

package
v0.19.1 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package aitools reads and writes the on-disk configuration that AI coding CLIs (Claude Code, Codex) keep in the user's home directory: skills, agents, slash commands and MCP server definitions.

Everything here talks to an undocumented, private on-disk layout owned by those tools. Parsing is therefore deliberately lenient: a shape we do not recognize yields an empty result and a Warning the UI can surface, never a hard error and never a silent blank panel.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidName = fmt.Errorf("name must be a single path segment without separators")

ErrInvalidName is returned for a name that is not a single safe path segment.

Functions

func DeleteItem

func DeleteItem(kind Kind, scope Scope, name string, projectDir string) error

DeleteItem removes one item. For a skill this removes the whole skill directory, since a skill is a directory and leaving an empty one behind would keep it visible as a broken entry.

func ReadItem

func ReadItem(kind Kind, scope Scope, name string, projectDir string) (string, error)

ReadItem returns the markdown body of one item.

func WriteItem

func WriteItem(kind Kind, scope Scope, name string, projectDir string, content string) error

WriteItem creates or replaces one item, creating parent directories as needed. Files are 0600 and directories 0700: these hold prompts and agent instructions, which are the user's own content and not other users' business.

Types

type Inventory

type Inventory struct {
	Skills   []Item      `json:"skills"`
	Agents   []Item      `json:"agents"`
	Commands []Item      `json:"commands"`
	MCP      []MCPServer `json:"mcp"`
	// Warnings records anything that could not be read or parsed. A non-empty
	// Warnings with empty results is the signal that the on-disk format has
	// drifted, as opposed to the user simply having nothing configured.
	Warnings []string `json:"warnings,omitempty"`
}

Inventory is a full snapshot of the AI tool configuration.

func ReadInventory

func ReadInventory(projectDir string) (*Inventory, error)

ReadInventory collects every skill, agent, command and MCP server visible from projectDir. Pass an empty projectDir to read user scope only.

User and project scope are kept as separate entries rather than merged: which file defines a server is exactly what a user needs to know when two scopes disagree, and merging would hide that.

type Item

type Item struct {
	Kind Kind `json:"kind"`
	// Name is the addressable identifier: the directory name for a skill, the
	// filename without extension for an agent or command.
	Name        string `json:"name"`
	Scope       Scope  `json:"scope"`
	Path        string `json:"path"`
	Description string `json:"description,omitempty"`
	SizeBytes   int64  `json:"sizebytes"`
	ModTimeMs   int64  `json:"modtimems"`
}

Item is one skill, agent or slash command.

type Kind

type Kind string

Kind is the category of AI config item.

const (
	KindSkill   Kind = "skill"
	KindAgent   Kind = "agent"
	KindCommand Kind = "command"
)

type MCPServer

type MCPServer struct {
	Name string `json:"name"`
	// Transport is "stdio" when the entry runs a command, "http" when it
	// points at a URL. Derived, not stored on disk.
	Transport string            `json:"transport"`
	Command   string            `json:"command,omitempty"`
	Args      []string          `json:"args,omitempty"`
	URL       string            `json:"url,omitempty"`
	Env       map[string]string `json:"env,omitempty"`
	Scope     Scope             `json:"scope"`
	// SourcePath is the file the entry was read from, so the UI can say where
	// a server is defined when user and project scope disagree.
	SourcePath string `json:"sourcepath"`
}

MCPServer is one entry from an `mcpServers` map.

type Scope

type Scope string

Scope distinguishes config that lives in the user's home directory from config committed inside a project.

const (
	ScopeUser    Scope = "user"
	ScopeProject Scope = "project"
)

Jump to

Keyboard shortcuts

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