claude

package
v0.7.2 Latest Latest
Warning

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

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

Documentation

Overview

Package claude provides utilities for discovering and parsing team Claude customizations. It handles discovery of agents and commands from team context directories.

Index

Constants

View Source
const AgentsDir = "coworkers/agents"

AgentsDir is the path for agent definitions within a team context.

View Source
const CommandsDir = "coworkers/commands"

CommandsDir is the path for slash command definitions within a team context.

View Source
const CoworkersDir = "coworkers"

CoworkersDir is the base path for coworker customizations within a team context.

Variables

This section is empty.

Functions

func ParseIndex

func ParseIndex(path string) map[string]string

ParseIndex reads an index.md file and returns a map of name -> description. The index.md format is expected to be a simple list:

# Agents

- **agent-name**: Brief token-optimized description
- **other-agent**: Another description

Returns empty map if file doesn't exist or parsing fails.

func ParseIndexWithTable

func ParseIndexWithTable(path string) map[string]string

ParseIndexWithTable reads an index.md file that uses a markdown table format. Table format:

| Name | Description |
|------|-------------|
| agent-name | Brief description |

Returns empty map if file doesn't exist or parsing fails.

func ReadFirstLines added in v0.3.0

func ReadFirstLines(path string, maxLines int) string

ReadFirstLines reads up to maxLines lines from a file. Returns the content as a string, truncated at the line limit. Exported for reuse in prime output (e.g., MEMORY.md, AGENTS.md).

func ValidateAgentFile added in v0.3.0

func ValidateAgentFile(path string) (description, model string, err error)

ValidateAgentFile validates that a file is a valid coworker agent definition. Returns the parsed description and model, or an error if validation fails. Requires: YAML frontmatter with a description field.

Types

type Agent

type Agent struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Model       string `json:"model,omitempty"` // "inherit", "opus", "sonnet", "haiku"
	Path        string `json:"path"`            // absolute file path
	FromIndex   bool   `json:"from_index"`      // true if description came from index.md
}

Agent represents a Claude Code subagent definition from a team context.

func DiscoverAgents

func DiscoverAgents(teamPath string) ([]Agent, error)

DiscoverAgents finds all agents in a team context. Checks index.md first (token-optimized), falls back to individual files.

type AgentContent

type AgentContent struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Model       string `json:"model,omitempty"`
	Path        string `json:"path"`
	Content     string `json:"content"` // full markdown content
}

AgentContent holds the full content and metadata of an agent file.

func FindAgent

func FindAgent(teamPaths []string, name string) (*AgentContent, error)

FindAgent looks up an agent by name across all configured team contexts. Returns nil if the agent is not found.

func LoadAgent

func LoadAgent(teamPath, name string) (*AgentContent, error)

LoadAgent loads the full content of an agent file by name. Searches in the standard coworkers/agents/ directory. Returns the full file content along with parsed frontmatter metadata.

type Command

type Command struct {
	Name        string `json:"name"`        // command name (without /)
	Trigger     string `json:"trigger"`     // how to invoke (e.g., "/deploy")
	Description string `json:"description"` // what it does
	Path        string `json:"path"`        // absolute file path
	FromIndex   bool   `json:"from_index"`  // true if description came from index.md
}

Command represents a slash command defined in a team context.

func DiscoverTeamCommands

func DiscoverTeamCommands(teamPath string) ([]Command, error)

DiscoverTeamCommands finds all slash commands in a team context. It checks index.md first for token-optimized descriptions, then falls back to parsing individual command files for frontmatter.

Expected directory structure:

<team_context>/coworkers/commands/
├── index.md          # Optional: token-optimized descriptions
├── deploy.md         # /deploy command
└── review-pr.md      # /review-pr command

type TeamCustomizations

type TeamCustomizations struct {
	TeamPath string `json:"team_path"` // base path of team context

	// Instruction files (CLAUDE.md, AGENTS.md) in coworkers/
	ClaudeMDPath string `json:"claude_md_path,omitempty"` // coworkers/CLAUDE.md
	AgentsMDPath string `json:"agents_md_path,omitempty"` // coworkers/AGENTS.md
	HasClaudeMD  bool   `json:"has_claude_md"`
	HasAgentsMD  bool   `json:"has_agents_md"`

	// Agents-level AGENTS.md (coworkers/agents/AGENTS.md)
	// Content is read (first MaxAgentsMDLines lines) and inlined into prime output.
	AgentsAgentsMDPath    string `json:"agents_agents_md_path,omitempty"` // coworkers/agents/AGENTS.md
	AgentsAgentsMDContent string `json:"agents_agents_md_content,omitempty"`
	HasAgentsAgentsMD     bool   `json:"has_agents_agents_md,omitempty"`

	// Agents index (coworkers/agents/index.md)
	HasAgentsIndex  bool   `json:"has_agents_index,omitempty"`
	AgentsIndexPath string `json:"agents_index_path,omitempty"` // path to index.md if exists

	// Discovered items
	Agents   []Agent   `json:"agents,omitempty"`
	Commands []Command `json:"commands,omitempty"`
}

TeamCustomizations holds all coworker customizations discovered from a team context.

func DiscoverAll

func DiscoverAll(teamPath string) (*TeamCustomizations, error)

DiscoverAll finds all Claude customizations in a team context path. This is the main entry point for discovering team Claude customizations.

func (*TeamCustomizations) HasAnyCustomizations

func (tc *TeamCustomizations) HasAnyCustomizations() bool

HasAnyCustomizations returns true if any customizations were discovered.

func (*TeamCustomizations) HasInstructionFiles

func (tc *TeamCustomizations) HasInstructionFiles() bool

HasInstructionFiles returns true if either CLAUDE.md or AGENTS.md exists.

Jump to

Keyboard shortcuts

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