initialize

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package initialize provides utilities for initializing Spectr in a project directory.

Package initialize provides filesystem operations and configuration utilities for initializing Spectr projects.

Package initialize provides initialization functionality for Spectr, including an interactive wizard for project setup and gradient rendering utilities for enhanced visual presentation.

Index

Constants

View Source
const (

	// Marker constants for managing config/prompt file updates
	SpectrStartMarker = "<!-- spectr:START -->"
	SpectrEndMarker   = "<!-- spectr:END -->"

	// PopulateContextPrompt is the suggested prompt for users to populate
	// their project context.
	//
	// This prompt is also used to populate the user's clipboard when/if
	// they choose to copy the prompt to their clipboard in the init UI.
	PopulateContextPrompt = `` /* 153-byte string literal not displayed */

)

Variables

This section is empty.

Functions

func BackupFile

func BackupFile(path string) error

BackupFile creates a backup of an existing file with a timestamp suffix. The backup file name format is: original_name.backup.YYYYMMDD_HHMMSS.NNNNNNNNN If the file doesn't exist, no backup is created and no error is returned.

Returns an error if the backup operation fails.

func EnsureDir

func EnsureDir(path string) error

EnsureDir creates a directory and all parent directories if they don't exist. It is idempotent - no error is returned if the directory already exists. Directories are created with dirPerms permissions (rwxr-xr-x).

Returns an error if directory creation fails.

func ExpandPath

func ExpandPath(path string) (string, error)

ExpandPath expands a path that may contain ~ for home directory or relative paths. It handles: - Home directory expansion (~/) - Relative paths (converts to absolute) - Absolute paths (returns as-is)

Returns an absolute path or an error if expansion fails.

func FileExists

func FileExists(path string) bool

FileExists checks if a file or directory exists at the given path. Returns false if the path doesn't exist or if there's an error checking.

func FormatNextStepsMessage

func FormatNextStepsMessage() string

FormatNextStepsMessage returns a formatted next steps message for display after initialization

func IsSpectrInitialized

func IsSpectrInitialized(
	projectPath string,
) bool

IsSpectrInitialized checks if Spectr is already initialized in the project. It looks for the "spectr/project.md" file in the project directory.

Returns true if the project is already initialized, false otherwise.

func UpdateFileWithMarkers

func UpdateFileWithMarkers(
	filePath, content, startMarker, endMarker string,
) error

UpdateFileWithMarkers updates a file with content between markers. If the file doesn't exist, creates it with markers. If the file exists, updates content between markers.

Marker behavior:

  • Both markers found: Updates content between them
  • No markers found: Prepends content with markers
  • Only one marker found: Returns error (invalid state)

The markers must be on their own line (only whitespace around them).

Example usage:

err := UpdateFileWithMarkers(
    "CLAUDE.md",
    "# Instructions\nFollow these rules...",
    SpectrStartMarker,
    SpectrEndMarker,
)

func WriteFile

func WriteFile(
	path string,
	content []byte,
) error

WriteFile writes content to a file with filePerms permissions (rw-r--r--). It creates parent directories if needed. Returns an error if the file already exists to prevent accidental overwrites.

Use BackupFile before calling WriteFile if you want to preserve existing files.

Types

type ExecutionCompleteMsg

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

ExecutionCompleteMsg is sent when execution finishes

type ExecutionResult

type ExecutionResult struct {
	CreatedFiles []string
	UpdatedFiles []string
	Errors       []string
}

ExecutionResult holds the result of initialization

type InitCmd

type InitCmd struct {
	Path           string   `arg:"" optional:"" help:"Project path"`
	PathFlag       string   `                   help:"Alt project path"        name:"path"            short:"p"` //nolint:lll,revive // Kong struct tag with alignment
	Tools          []string `                   help:"Tools list"              name:"tools"           short:"t"` //nolint:lll,revive // Kong struct tag with alignment
	NonInteractive bool     `                   help:"Non-interactive"         name:"non-interactive"`           //nolint:lll,revive // Kong struct tag exceeds line length
	CIWorkflow     bool     `                   help:"Create CI workflow file" name:"ci-workflow"`               //nolint:lll,revive // Kong struct tag exceeds line length
}

InitCmd represents the init command with all its flags

type InitExecutor

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

InitExecutor handles the actual initialization process using the new provider architecture

func NewInitExecutor

func NewInitExecutor(
	cmd *InitCmd,
) (*InitExecutor, error)

NewInitExecutor creates a new initialization executor

func (*InitExecutor) Execute

func (e *InitExecutor) Execute(
	selectedProviderIDs []string,
	ciWorkflowEnabled bool,
) (*ExecutionResult, error)

Execute runs the initialization process using the new provider architecture

type InitState

type InitState int

InitState represents the current state of the initialization process

const (
	// StateSelectTools is the tool selection screen
	StateSelectTools InitState = iota
	// StateConfigureTools is the tool configuration screen
	StateConfigureTools
	// StateConfirmation is the final confirmation screen
	StateConfirmation
	// StateComplete is the completion state
	StateComplete
)

type ProjectConfig

type ProjectConfig struct {
	// ProjectPath is the absolute path to the project directory
	ProjectPath string
	// SelectedTools is the list of tools the user has selected to configure
	SelectedTools []string
	// SpectrEnabled indicates whether Spectr framework should be initialized
	SpectrEnabled bool
}

ProjectConfig holds the overall project configuration during init

type ProjectContext

type ProjectContext struct {
	// ProjectName is the name of the project
	ProjectName string
	// Description is the project description/purpose
	Description string
	// TechStack is the list of technologies used
	TechStack []string
	// Conventions are the project conventions (unused in template currently)
	Conventions string
}

ProjectContext holds template variables for rendering project.md

type TemplateManager

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

TemplateManager manages embedded templates for initialization

func NewTemplateManager

func NewTemplateManager() (*TemplateManager, error)

NewTemplateManager creates a new template manager with all embedded templates loaded. It merges templates from: 1. internal/initialize/templates (main templates: AGENTS.md, instruction-pointer.md) 2. internal/domain (slash command templates: slash-proposal.md, slash-apply.md, TOML variants)

func (*TemplateManager) Agents added in v0.0.9

func (tm *TemplateManager) Agents() domain.TemplateRef

Agents returns a type-safe reference to the AGENTS.md.tmpl template

func (*TemplateManager) InstructionPointer added in v0.0.9

func (tm *TemplateManager) InstructionPointer() domain.TemplateRef

InstructionPointer returns a type-safe reference to the instruction-pointer.md.tmpl template

func (*TemplateManager) RenderAgents

func (tm *TemplateManager) RenderAgents(
	ctx *domain.TemplateContext,
) (string, error)

RenderAgents renders the AGENTS.md template with the given template context The context provides path variables for dynamic directory names

func (*TemplateManager) RenderCIWorkflow

func (tm *TemplateManager) RenderCIWorkflow() (string, error)

RenderCIWorkflow renders the spectr-ci.yml template for GitHub Actions This template has no variables and returns the CI workflow configuration

func (*TemplateManager) RenderInstructionPointer

func (tm *TemplateManager) RenderInstructionPointer(
	ctx *domain.TemplateContext,
) (string, error)

RenderInstructionPointer renders the instruction-pointer.md template This is a short pointer that directs AI assistants to read the AGENTS.md file The context provides path variables for dynamic directory names

func (*TemplateManager) RenderProject

func (tm *TemplateManager) RenderProject(
	ctx ProjectContext,
) (string, error)

RenderProject renders the project.md template with the given context

func (*TemplateManager) RenderSlashCommand

func (tm *TemplateManager) RenderSlashCommand(
	commandType string,
	ctx *domain.TemplateContext,
) (string, error)

RenderSlashCommand renders a slash command template with the given context commandType must be one of: "proposal", "apply", "archive" The context provides path variables for dynamic directory names

func (*TemplateManager) SkillFS added in v0.0.9

func (*TemplateManager) SkillFS(skillName string) (fs.FS, error)

SkillFS returns an fs.FS rooted at the skill directory for the given skill name. Returns an error if the skill does not exist. The filesystem contains all files under templates/skills/<skillName>/ with paths relative to the skill root (e.g., SKILL.md, scripts/accept.sh).

func (*TemplateManager) SlashCommand added in v0.0.9

func (tm *TemplateManager) SlashCommand(cmd domain.SlashCommand) domain.TemplateRef

SlashCommand returns a Markdown template reference for the given slash command type. Used by SlashCommandsInitializer, HomeSlashCommandsInitializer, and PrefixedSlashCommandsInitializer.

func (*TemplateManager) TOMLSlashCommand added in v0.0.9

func (tm *TemplateManager) TOMLSlashCommand(cmd domain.SlashCommand) domain.TemplateRef

TOMLSlashCommand returns a TOML template reference for the given slash command type. Used by TOMLSlashCommandsInitializer (Gemini only).

type WizardModel

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

WizardModel is the Bubbletea model for the init wizard

func NewWizardModel

func NewWizardModel(
	cmd *InitCmd,
) (*WizardModel, error)

NewWizardModel creates a new wizard model

func (*WizardModel) GetError

func (m *WizardModel) GetError() error

GetError returns the error from the wizard (if any)

func (*WizardModel) Init

func (*WizardModel) Init() tea.Cmd

Init is the Bubbletea Init function

func (*WizardModel) Update

func (m *WizardModel) Update(
	msg tea.Msg,
) (tea.Model, tea.Cmd)

Update is the Bubbletea Update function

func (*WizardModel) View

func (m *WizardModel) View() string

View is the Bubbletea View function

type WizardStep

type WizardStep int

WizardStep represents the current step in the wizard

const (
	StepIntro WizardStep = iota
	StepSelect
	StepReview
	StepExecute
	StepComplete
)

Directories

Path Synopsis
Package providers implements the composable initializer architecture for AI CLI/IDE/Orchestrator tools.
Package providers implements the composable initializer architecture for AI CLI/IDE/Orchestrator tools.

Jump to

Keyboard shortcuts

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