build

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package build orchestrates the coding agent integration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdvanceStep

func AdvanceStep(db *store.DB, session *SessionState) error

AdvanceStep marks the current step as complete and moves to the next.

func LogActivity

func LogActivity(specID, entry string) error

LogActivity appends an entry to both the SQLite activity log and the session file.

func SaveSession

func SaveSession(db *store.DB, session *SessionState) error

SaveSession persists a session to the database.

func SessionDir

func SessionDir(specID string) string

SessionDir returns the path to the session directory.

func SetActivityDB

func SetActivityDB(db *store.DB)

SetActivityDB sets the database used for activity logging.

func ToolDefinitions

func ToolDefinitions() []map[string]interface{}

ToolDefinitions returns the MCP tool definitions for advertising.

func WriteContextFile

func WriteContextFile(ctx *BuildContext, outputPath string) error

WriteContextFile writes a consolidated context markdown file for non-MCP agents.

Types

type BuildContext

type BuildContext struct {
	SpecPath     string
	SpecContent  string
	PriorDiffs   []string
	FailingTests string
	Conventions  string
	CurrentStep  PRStep
	SystemPrompt string
	// Skills holds the resolved skill bodies (Agent Skills markdown). Empty
	// when no skills are present under .spec/agent/skills/ or in config.
	Skills []string
}

BuildContext is the assembled context payload passed to an agent.

func AssembleContext

func AssembleContext(specPath string, session *SessionState, conventions string) (*BuildContext, error)

AssembleContext builds the full context payload for an agent.

type Engine

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

Engine orchestrates the build process.

func NewEngine

func NewEngine(db *store.DB, agent adapter.AgentAdapter, opts Options) *Engine

NewEngine creates a new build engine.

func (*Engine) StartOrResume

func (e *Engine) StartOrResume(ctx context.Context, specID, specPath, startDir string) error

StartOrResume begins or continues a build session for a spec. It walks the PR stack one step at a time, automatically moving into each step's target repository (via configured workspaces) so a multi-repo spec can be executed end-to-end. It advances to the next step only when the current one is completed (via MCP or the interactive prompt); if a step is left unfinished it stops so the user can resume later with `spec do`.

type MCPResource

type MCPResource struct {
	URI     string `json:"uri"`
	Name    string `json:"name"`
	Content string `json:"content"`
}

MCPResource represents a resource served by the MCP server.

type MCPServer

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

MCPServer serves spec context to MCP-compatible agents. This is a simplified implementation that handles the core resource/tool protocol.

func NewMCPServer

func NewMCPServer(session *SessionState, buildCtx *BuildContext, db *store.DB, specPath string) *MCPServer

NewMCPServer creates a new MCP server for a build session.

func (*MCPServer) CallTool

func (s *MCPServer) CallTool(name string, args json.RawMessage) (*MCPToolResult, error)

CallTool executes an MCP tool.

func (*MCPServer) GetResource

func (s *MCPServer) GetResource(uri string) (*MCPResource, error)

GetResource returns a specific resource by URI.

func (*MCPServer) ListResources

func (s *MCPServer) ListResources() []MCPResource

ListResources returns all available resources.

type MCPToolResult

type MCPToolResult struct {
	Success bool   `json:"success"`
	Message string `json:"message"`
}

MCPToolResult represents the result of an MCP tool call.

type Options added in v0.15.0

type Options struct {
	// Headless runs the agent autonomously (e.g. `spec fix --auto`).
	Headless bool
	// SkillRefs are explicit skill paths from config
	// (integrations.agent.settings.skill). They take precedence over
	// profile.yaml refs and the .spec/agent/skills/ directory.
	SkillRefs []string
	// TestCommand, when set, is run to populate FailingTests (best-effort).
	TestCommand string
	// Workspaces maps a PR-step repo name to a local directory, letting the
	// engine move into the right repo for each step of a multi-repo build.
	Workspaces map[string]string
}

Options configures a build engine beyond its adapters.

type PRStep

type PRStep struct {
	Number      int    `yaml:"number" json:"number"`
	Repo        string `yaml:"repo" json:"repo"`
	Description string `yaml:"description" json:"description"`
	Branch      string `yaml:"branch" json:"branch"`
	Status      string `yaml:"status" json:"status"` // "pending", "in-progress", "complete"
	// BaseRef is the commit the step branch was created from. Used to capture
	// the step's diff for cumulative cross-step context.
	BaseRef string `yaml:"base_ref" json:"base_ref,omitempty"`
}

PRStep represents one step in the PR stack plan.

func ParsePRStack

func ParsePRStack(content string) ([]PRStep, error)

ParsePRStack extracts PR steps from the §7.3 PR Stack Plan section.

func ParsePRStackFromFile

func ParsePRStackFromFile(path string) ([]PRStep, error)

ParsePRStackFromFile reads a spec file and extracts PR steps.

type SessionState

type SessionState struct {
	SpecID       string    `json:"spec_id"`
	CurrentStep  int       `json:"current_step"`
	Branch       string    `json:"branch"`
	Repo         string    `json:"repo"`
	WorkDir      string    `json:"work_dir"`
	LastActivity time.Time `json:"last_activity"`
	Steps        []PRStep  `json:"steps"`
}

SessionState persists the build session for `spec do` resume.

func CreateSession

func CreateSession(db *store.DB, specID string, steps []PRStep, workDir string) (*SessionState, error)

CreateSession creates a new build session.

func LoadSession

func LoadSession(db *store.DB, specID string) (*SessionState, error)

LoadSession loads a session from the database.

func (*SessionState) CurrentPRStep

func (s *SessionState) CurrentPRStep() *PRStep

CurrentPRStep returns the current step, or nil if complete.

func (*SessionState) IsComplete

func (s *SessionState) IsComplete() bool

IsComplete returns true if all steps are done.

Jump to

Keyboard shortcuts

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