context

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package context provides dependency injection for workflow services.

Core types:

  • Services: Collection of all devflow services for injection
  • ContextBuilder: Builds LLM context from files with size limits
  • FileSelector: Selects files for context based on patterns
  • ContextLimits: Token and size limits for context building

Context injection functions:

  • WithGit/Git: Git context injection
  • WithLLM/LLM: LLM client injection (flowgraph claude.Client)
  • WithTranscript/Transcript: Transcript manager injection
  • WithArtifact/Artifact: Artifact manager injection
  • WithNotifier/Notifier: Notifier injection
  • WithRunner/Runner: Command runner injection (for testing)

Example usage:

services := &context.Services{
    Git:      gitCtx,
    LLM:      llmClient,
    Notifier: slackNotifier,
}
ctx := services.InjectAll(ctx)

// Later, retrieve services
git := context.Git(ctx)
llm := context.LLM(ctx)

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrContextTooLarge indicates the context exceeds size limits.
	ErrContextTooLarge = errors.New("context too large")
)

Context building errors

Functions

func Artifact

func Artifact(ctx context.Context) *artifact.Manager

Artifact extracts artifact manager from context

func GetRunner

func GetRunner(ctx context.Context) git.CommandRunner

GetRunner returns the command runner from context, or a default ExecRunner. This is the preferred way for nodes to get a runner - it always returns a usable runner.

func Git

func Git(ctx context.Context) *git.Context

Git extracts Git context from context

func LLM

func LLM(ctx context.Context) claude.Client

LLM extracts the LLM client from context.

func MustArtifact

func MustArtifact(ctx context.Context) *artifact.Manager

MustArtifact extracts artifact manager or panics

func MustGit

func MustGit(ctx context.Context) *git.Context

MustGit extracts Git context or panics

func MustLLM

func MustLLM(ctx context.Context) claude.Client

MustLLM extracts the LLM client or panics.

func MustPR

func MustPR(ctx context.Context) pr.Provider

MustPR extracts PR provider or panics

func MustPrompt

func MustPrompt(ctx context.Context) *prompt.Loader

MustPrompt extracts prompt loader or panics

func MustTranscript

func MustTranscript(ctx context.Context) transcript.Manager

MustTranscript extracts transcript manager or panics

func PR

func PR(ctx context.Context) pr.Provider

PR extracts PR provider from context

func Prompt

func Prompt(ctx context.Context) *prompt.Loader

Prompt extracts prompt loader from context

func Runner

func Runner(ctx context.Context) git.CommandRunner

Runner extracts command runner from context. Returns nil if not set - callers should fall back to ExecRunner.

func Transcript

func Transcript(ctx context.Context) transcript.Manager

Transcript extracts transcript manager from context

func WithArtifact

func WithArtifact(ctx context.Context, mgr *artifact.Manager) context.Context

WithArtifact adds an artifact manager to the context

func WithGit

func WithGit(ctx context.Context, gitCtx *git.Context) context.Context

WithGit adds a Git context to the context

func WithLLM

func WithLLM(ctx context.Context, client claude.Client) context.Context

WithLLM adds an LLM client to the context. This uses flowgraph's claude.Client interface.

func WithPR

func WithPR(ctx context.Context, provider pr.Provider) context.Context

WithPR adds a PR provider to the context

func WithPrompt

func WithPrompt(ctx context.Context, loader *prompt.Loader) context.Context

WithPrompt adds a prompt loader to the context

func WithRunner

func WithRunner(ctx context.Context, runner git.CommandRunner) context.Context

WithRunner adds a command runner to the context. This allows nodes to execute shell commands through a mockable interface.

func WithTranscript

func WithTranscript(ctx context.Context, mgr transcript.Manager) context.Context

WithTranscript adds a transcript manager to the context

Types

type Config

type Config struct {
	RepoPath  string // Path to git repository (required)
	BaseDir   string // Base directory for storage (default: ".devflow")
	PromptDir string // Directory for prompt templates (default: ".devflow/prompts")

	// LLM configuration
	LLMModel   string // Model to use (default: "claude-sonnet-4-20250514")
	LLMWorkdir string // Working directory for LLM (default: RepoPath)
}

Config configures NewServices

type ContextBuilder

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

ContextBuilder builds file context for Claude.

func NewContextBuilder

func NewContextBuilder(workDir string) *ContextBuilder

NewContextBuilder creates a context builder for the given working directory.

func (*ContextBuilder) AddContent

func (b *ContextBuilder) AddContent(path string, content []byte)

AddContent adds pre-loaded content with a virtual path.

func (*ContextBuilder) AddFile

func (b *ContextBuilder) AddFile(path string) error

AddFile adds a single file to the context.

func (*ContextBuilder) AddGlob

func (b *ContextBuilder) AddGlob(pattern string) error

AddGlob adds files matching a glob pattern.

func (*ContextBuilder) Build

func (b *ContextBuilder) Build() (string, error)

Build generates the formatted context string.

func (*ContextBuilder) Clear

func (b *ContextBuilder) Clear()

Clear removes all files from the builder.

func (*ContextBuilder) FileCount

func (b *ContextBuilder) FileCount() int

FileCount returns the number of files added.

func (*ContextBuilder) TotalSize

func (b *ContextBuilder) TotalSize() int64

TotalSize returns the total size of all files.

func (*ContextBuilder) WithLimits

func (b *ContextBuilder) WithLimits(limits ContextLimits) *ContextBuilder

WithLimits sets custom context limits.

type ContextLimits

type ContextLimits struct {
	MaxFileSize  int64 // Max size per file in bytes
	MaxTotalSize int64 // Max total size in bytes
	MaxFileCount int   // Max number of files
}

ContextLimits configures file context limits.

func DefaultContextLimits

func DefaultContextLimits() ContextLimits

DefaultContextLimits returns sensible default limits.

type FileSelector

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

FileSelector helps select relevant files for context.

func NewFileSelector

func NewFileSelector(workDir string) *FileSelector

NewFileSelector creates a file selector for the given directory.

func (*FileSelector) Exclude

func (s *FileSelector) Exclude(patterns ...string) *FileSelector

Exclude adds exclude patterns.

func (*FileSelector) Include

func (s *FileSelector) Include(patterns ...string) *FileSelector

Include adds include patterns.

func (*FileSelector) Select

func (s *FileSelector) Select() ([]string, error)

Select returns files matching the include patterns but not the exclude patterns.

type Services

type Services struct {
	Git         *git.Context
	LLM         claude.Client // flowgraph claude.Client interface
	Transcripts transcript.Manager
	Artifacts   *artifact.Manager
	Prompts     *prompt.Loader
	Notifier    notify.Notifier   // Optional notification service
	Runner      git.CommandRunner // Optional command runner (defaults to ExecRunner)
}

Services wraps all devflow services for convenient initialization

func NewServices

func NewServices(cfg Config) (*Services, error)

NewServices creates Services with common defaults

func (*Services) InjectAll

func (s *Services) InjectAll(ctx context.Context) context.Context

InjectAll adds all configured services to the context

Jump to

Keyboard shortcuts

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