Documentation
¶
Overview ¶
Package core provides the canonical types for project context that can be converted to various AI assistant formats (CLAUDE.md, .cursorrules, etc.).
Index ¶
- Constants
- Variables
- func ConvertTo(ctx *Context, format string) ([]byte, error)
- func RegisterConverter(converter Converter)
- type Architecture
- type BaseConverter
- type Context
- func (c *Context) AddConvention(convention string)
- func (c *Context) AddNote(content string)
- func (c *Context) AddNoteWithSeverity(title, content, severity string)
- func (c *Context) AddPackage(path, purpose string)
- func (c *Context) Marshal() ([]byte, error)
- func (c *Context) SetCommand(name, command string)
- func (c *Context) WriteFile(path string) error
- func (c *Context) WriteFileWithMode(path string, mode os.FileMode) error
- type ConversionError
- type Converter
- type ConverterRegistry
- func (r *ConverterRegistry) Convert(ctx *Context, format string) ([]byte, error)
- func (r *ConverterRegistry) GenerateAll(ctx *Context, dir string) error
- func (r *ConverterRegistry) Get(name string) (Converter, bool)
- func (r *ConverterRegistry) Names() []string
- func (r *ConverterRegistry) Register(converter Converter)
- func (r *ConverterRegistry) WriteFile(ctx *Context, format, path string) error
- type Dependencies
- type Dependency
- type Diagram
- type Files
- type Note
- type Package
- type ParseError
- type Related
- type Testing
- type WriteError
Constants ¶
const DefaultFileMode fs.FileMode = 0600
DefaultFileMode is the default permission mode for generated files. This can be used by converters or overridden with WriteFileWithDataAndMode.
Variables ¶
var ( // ErrEmptyContext is returned when the context is empty. ErrEmptyContext = errors.New("context is empty") // ErrMissingName is returned when the context name is missing. ErrMissingName = errors.New("context name is required") // ErrUnsupportedFormat is returned when a format is not supported. ErrUnsupportedFormat = errors.New("unsupported output format") )
Common errors for context operations.
var DefaultRegistry = NewConverterRegistry()
DefaultRegistry is the global converter registry.
Functions ¶
func RegisterConverter ¶
func RegisterConverter(converter Converter)
RegisterConverter adds a converter to the default registry.
Types ¶
type Architecture ¶
type Architecture struct {
// Pattern is the primary architectural pattern (e.g., "adapter", "hexagonal").
Pattern string `json:"pattern,omitempty"`
// Summary is a brief summary of the architecture.
Summary string `json:"summary,omitempty"`
// Diagrams contains ASCII or mermaid diagrams.
Diagrams []Diagram `json:"diagrams,omitempty"`
}
Architecture describes the high-level architecture of the project.
type BaseConverter ¶
type BaseConverter struct {
// contains filtered or unexported fields
}
BaseConverter provides common functionality for converters.
func NewBaseConverter ¶
func NewBaseConverter(name, outputFile string) BaseConverter
NewBaseConverter creates a new base converter.
func (*BaseConverter) OutputFileName ¶
func (c *BaseConverter) OutputFileName() string
OutputFileName returns the default output file name.
func (*BaseConverter) WriteFileWithData ¶
func (c *BaseConverter) WriteFileWithData(data []byte, path string) error
WriteFileWithData writes data to a file with proper error wrapping using DefaultFileMode.
func (*BaseConverter) WriteFileWithDataAndMode ¶
WriteFileWithDataAndMode writes data to a file with proper error wrapping using the specified permission mode.
type Context ¶
type Context struct {
// Schema is the JSON Schema reference for validation.
Schema string `json:"$schema,omitempty"`
// Name is the project name.
Name string `json:"name"`
// Description is a brief description of the project's purpose.
Description string `json:"description,omitempty"`
// Version is the current project version.
Version string `json:"version,omitempty"`
// Language is the primary programming language.
Language string `json:"language,omitempty"`
// Architecture describes the high-level architecture.
Architecture *Architecture `json:"architecture,omitempty"`
// Packages lists key packages/modules and their purposes.
Packages []Package `json:"packages,omitempty"`
// Commands contains common commands for working with the project.
Commands map[string]string `json:"commands,omitempty"`
// Conventions lists coding conventions and patterns.
Conventions []string `json:"conventions,omitempty"`
// Dependencies describes key dependencies.
Dependencies *Dependencies `json:"dependencies,omitempty"`
// Testing describes the testing strategy.
Testing *Testing `json:"testing,omitempty"`
// Files describes important files.
Files *Files `json:"files,omitempty"`
// Notes contains additional notes and gotchas.
Notes []Note `json:"notes,omitempty"`
// Related lists related projects or resources.
Related []Related `json:"related,omitempty"`
}
Context represents the canonical project context that can be converted to various AI assistant formats.
func (*Context) AddConvention ¶
AddConvention adds a convention to the context.
func (*Context) AddNoteWithSeverity ¶
AddNoteWithSeverity adds a note with a specific severity.
func (*Context) AddPackage ¶
AddPackage adds a package to the context.
func (*Context) SetCommand ¶
SetCommand sets a command.
type ConversionError ¶
ConversionError represents an error converting to a specific format.
func (*ConversionError) Error ¶
func (e *ConversionError) Error() string
func (*ConversionError) Unwrap ¶
func (e *ConversionError) Unwrap() error
type Converter ¶
type Converter interface {
// Name returns the converter name (e.g., "claude", "cursor").
Name() string
// OutputFileName returns the default output file name (e.g., "CLAUDE.md").
OutputFileName() string
// Convert converts the context to the tool-specific format.
Convert(ctx *Context) ([]byte, error)
// WriteFile writes the converted context to a file.
WriteFile(ctx *Context, path string) error
}
Converter defines the interface for converting project context to tool-specific formats.
func GetConverter ¶
GetConverter returns a converter from the default registry.
type ConverterRegistry ¶
type ConverterRegistry struct {
// contains filtered or unexported fields
}
ConverterRegistry holds registered converters for different tools.
func NewConverterRegistry ¶
func NewConverterRegistry() *ConverterRegistry
NewConverterRegistry creates a new converter registry.
func (*ConverterRegistry) Convert ¶
func (r *ConverterRegistry) Convert(ctx *Context, format string) ([]byte, error)
Convert converts a context to a specific format.
func (*ConverterRegistry) GenerateAll ¶
func (r *ConverterRegistry) GenerateAll(ctx *Context, dir string) error
GenerateAll generates all supported formats in the given directory.
func (*ConverterRegistry) Get ¶
func (r *ConverterRegistry) Get(name string) (Converter, bool)
Get returns a converter by name.
func (*ConverterRegistry) Names ¶
func (r *ConverterRegistry) Names() []string
Names returns the names of all registered converters.
func (*ConverterRegistry) Register ¶
func (r *ConverterRegistry) Register(converter Converter)
Register adds a converter to the registry.
type Dependencies ¶
type Dependencies struct {
// Runtime lists runtime dependencies.
Runtime []Dependency `json:"runtime,omitempty"`
// Development lists development dependencies.
Development []Dependency `json:"development,omitempty"`
}
Dependencies describes the project's dependencies.
type Dependency ¶
type Dependency struct {
// Name is the dependency name/identifier.
Name string `json:"name"`
// Purpose describes what this dependency is used for.
Purpose string `json:"purpose,omitempty"`
}
Dependency represents a single dependency.
type Diagram ¶
type Diagram struct {
// Title is the diagram title.
Title string `json:"title,omitempty"`
// Type is the diagram type ("ascii" or "mermaid").
Type string `json:"type,omitempty"`
// Content is the diagram content.
Content string `json:"content"`
}
Diagram represents an architecture diagram.
type Files ¶
type Files struct {
// EntryPoints lists main entry point files.
EntryPoints []string `json:"entryPoints,omitempty"`
// Config lists configuration files.
Config []string `json:"config,omitempty"`
// Ignore lists files/patterns to ignore during analysis.
Ignore []string `json:"ignore,omitempty"`
}
Files describes important files in the project.
type Note ¶
type Note struct {
// Title is an optional title for the note.
Title string `json:"title,omitempty"`
// Content is the note content.
Content string `json:"content"`
// Severity indicates the importance (info, warning, critical).
Severity string `json:"severity,omitempty"`
}
Note represents an additional note or gotcha.
func (*Note) GetSeverity ¶
GetSeverity returns the severity, defaulting to "info".
type Package ¶
type Package struct {
// Path is the relative path to the package.
Path string `json:"path"`
// Purpose is a brief description of the package's purpose.
Purpose string `json:"purpose"`
// Public indicates whether this is part of the public API.
Public *bool `json:"public,omitempty"`
}
Package describes a package or module in the project.
type ParseError ¶
ParseError represents an error parsing a context file.
func (*ParseError) Error ¶
func (e *ParseError) Error() string
func (*ParseError) Unwrap ¶
func (e *ParseError) Unwrap() error
type Related ¶
type Related struct {
// Name is the name of the related item.
Name string `json:"name"`
// URL is an optional URL.
URL string `json:"url,omitempty"`
// Description is an optional description.
Description string `json:"description,omitempty"`
}
Related represents a related project or resource.
type Testing ¶
type Testing struct {
// Framework is the testing framework used.
Framework string `json:"framework,omitempty"`
// Coverage describes coverage requirements or current coverage.
Coverage string `json:"coverage,omitempty"`
// Patterns lists testing patterns and conventions.
Patterns []string `json:"patterns,omitempty"`
}
Testing describes the testing strategy.
type WriteError ¶
WriteError represents an error writing a context file.
func (*WriteError) Error ¶
func (e *WriteError) Error() string
func (*WriteError) Unwrap ¶
func (e *WriteError) Unwrap() error