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 ¶
- Variables
- func Artifact(ctx context.Context) *artifact.Manager
- func GetRunner(ctx context.Context) git.CommandRunner
- func Git(ctx context.Context) *git.Context
- func LLM(ctx context.Context) claude.Client
- func MustArtifact(ctx context.Context) *artifact.Manager
- func MustGit(ctx context.Context) *git.Context
- func MustLLM(ctx context.Context) claude.Client
- func MustPR(ctx context.Context) pr.Provider
- func MustPrompt(ctx context.Context) *prompt.Loader
- func MustTranscript(ctx context.Context) transcript.Manager
- func PR(ctx context.Context) pr.Provider
- func Prompt(ctx context.Context) *prompt.Loader
- func Runner(ctx context.Context) git.CommandRunner
- func Transcript(ctx context.Context) transcript.Manager
- func WithArtifact(ctx context.Context, mgr *artifact.Manager) context.Context
- func WithGit(ctx context.Context, gitCtx *git.Context) context.Context
- func WithLLM(ctx context.Context, client claude.Client) context.Context
- func WithPR(ctx context.Context, provider pr.Provider) context.Context
- func WithPrompt(ctx context.Context, loader *prompt.Loader) context.Context
- func WithRunner(ctx context.Context, runner git.CommandRunner) context.Context
- func WithTranscript(ctx context.Context, mgr transcript.Manager) context.Context
- type Config
- type ContextBuilder
- func (b *ContextBuilder) AddContent(path string, content []byte)
- func (b *ContextBuilder) AddFile(path string) error
- func (b *ContextBuilder) AddGlob(pattern string) error
- func (b *ContextBuilder) Build() (string, error)
- func (b *ContextBuilder) Clear()
- func (b *ContextBuilder) FileCount() int
- func (b *ContextBuilder) TotalSize() int64
- func (b *ContextBuilder) WithLimits(limits ContextLimits) *ContextBuilder
- type ContextLimits
- type FileSelector
- type Services
Constants ¶
This section is empty.
Variables ¶
var ( // ErrContextTooLarge indicates the context exceeds size limits. ErrContextTooLarge = errors.New("context too large") )
Context building errors
Functions ¶
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 MustArtifact ¶
MustArtifact extracts artifact manager or panics
func MustPrompt ¶
MustPrompt extracts prompt loader or panics
func MustTranscript ¶
func MustTranscript(ctx context.Context) transcript.Manager
MustTranscript extracts transcript manager or panics
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 ¶
WithArtifact adds an artifact manager to the context
func WithLLM ¶
WithLLM adds an LLM client to the context. This uses flowgraph's claude.Client interface.
func WithPrompt ¶
WithPrompt adds a prompt loader to the context
func WithRunner ¶
WithRunner adds a command runner to the context. This allows nodes to execute shell commands through a mockable interface.
func WithTranscript ¶
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 ¶
NewServices creates Services with common defaults