core

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: MIT Imports: 5 Imported by: 0

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

View Source
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

View Source
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.

View Source
var DefaultRegistry = NewConverterRegistry()

DefaultRegistry is the global converter registry.

Functions

func ConvertTo

func ConvertTo(ctx *Context, format string) ([]byte, error)

ConvertTo converts a context to a specific format using the default registry.

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) Name

func (c *BaseConverter) Name() string

Name returns the converter name.

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

func (c *BaseConverter) WriteFileWithDataAndMode(data []byte, path string, mode fs.FileMode) error

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 NewContext

func NewContext(name string) *Context

NewContext creates a new empty Context.

func Parse

func Parse(data []byte) (*Context, error)

Parse parses JSON data into a Context.

func ReadFile

func ReadFile(path string) (*Context, error)

ReadFile reads a Context from a JSON file.

func (*Context) AddConvention

func (c *Context) AddConvention(convention string)

AddConvention adds a convention to the context.

func (*Context) AddNote

func (c *Context) AddNote(content string)

AddNote adds a note to the context.

func (*Context) AddNoteWithSeverity

func (c *Context) AddNoteWithSeverity(title, content, severity string)

AddNoteWithSeverity adds a note with a specific severity.

func (*Context) AddPackage

func (c *Context) AddPackage(path, purpose string)

AddPackage adds a package to the context.

func (*Context) Marshal

func (c *Context) Marshal() ([]byte, error)

Marshal converts the Context to JSON.

func (*Context) SetCommand

func (c *Context) SetCommand(name, command string)

SetCommand sets a command.

func (*Context) WriteFile

func (c *Context) WriteFile(path string) error

WriteFile writes the Context to a JSON file using DefaultFileMode.

func (*Context) WriteFileWithMode

func (c *Context) WriteFileWithMode(path string, mode os.FileMode) error

WriteFileWithMode writes the Context to a JSON file with the specified permission mode.

type ConversionError

type ConversionError struct {
	Format string
	Err    error
}

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

func GetConverter(name string) (Converter, bool)

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.

func (*ConverterRegistry) WriteFile

func (r *ConverterRegistry) WriteFile(ctx *Context, format, path string) error

WriteFile writes a context to a file in a specific format.

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

func (n *Note) GetSeverity() string

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.

func (*Package) IsPublic

func (p *Package) IsPublic() bool

IsPublic returns whether the package is public (defaults to true).

type ParseError

type ParseError struct {
	Path string
	Err  error
}

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 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

type WriteError struct {
	Format string
	Path   string
	Err    error
}

WriteError represents an error writing a context file.

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