impl

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: MIT Imports: 63 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LangGo         = "go"
	LangRuby       = "ruby"
	LangJavaScript = "javascript"
	LangTypeScript = "typescript"
	LangTSX        = "tsx"
	LangPython     = "python"
	LangJava       = "java"
	LangRust       = "rust"
	LangC          = "c"
	LangCPP        = "cpp"
	LangCSharp     = "csharp"
	LangStarlark   = "starlark"
	LangProtobuf   = "protobuf"
	LangSQL        = "sql"
	LangYAML       = "yaml"
	LangMarkdown   = "markdown"
)

Language name constants.

Variables

View Source
var DefaultSkipDirs = map[string]bool{
	".git":         true,
	".venv":        true,
	".env":         true,
	"node_modules": true,
	"vendor":       true,
	"__pycache__":  true,
	"target":       true,
	"build":        true,
	"dist":         true,
}

DefaultSkipDirs lists directories that should be skipped during traversal.

View Source
var ExtensionToLanguage = map[string]string{
	".go":    LangGo,
	".rb":    LangRuby,
	".js":    LangJavaScript,
	".jsx":   LangJavaScript,
	".ts":    LangTypeScript,
	".tsx":   LangTSX,
	".py":    LangPython,
	".java":  LangJava,
	".rs":    LangRust,
	".c":     LangC,
	".h":     LangC,
	".cpp":   LangCPP,
	".cc":    LangCPP,
	".cxx":   LangCPP,
	".hpp":   LangCPP,
	".cs":    LangCSharp,
	".bzl":   LangStarlark,
	".bazel": LangStarlark,
	".proto": LangProtobuf,
	".sql":   LangSQL,
	".yaml":  LangYAML,
	".yml":   LangYAML,
	".md":    LangMarkdown,
}

ExtensionToLanguage maps file extensions to language names.

Functions

func FilterReviewableFiles

func FilterReviewableFiles(files []services.PRFileInfo) []services.PRFileInfo

FilterReviewableFiles returns only the files that need AI review, excluding docs, lockfiles, images, and generated code.

func GetToolDefinitions

func GetToolDefinitions() []anthropic.ToolUnionParam

func NewAnthropicReviewer

func NewAnthropicReviewer(
	apiKey string,
	model string,
	maxTokens int,
	maxTurns int,
	executor *ToolExecutor,
	promptProvider *PromptProvider,
	logger *zap.Logger,
) services.Reviewer

func NewEmbedderService

func NewEmbedderService(cfg config.OpenAIConfig, logger *zap.Logger) (services.EmbedderService, error)

func NewEmbedderWithSemaphore

func NewEmbedderWithSemaphore(inner services.EmbedderService, logger *zap.Logger, indexerCfg config.IndexerConfig) services.EmbedderService

NewEmbedderWithSemaphore returns an EmbedderService that caps concurrent Embed / EmbedSingle calls at indexerCfg.EmbeddingConcurrency() and wraps OpenAI 4xx errors as services.Terminal("openai_embed", ...). Registered as a dig decorator so dig.Provide(NewEmbedderService) is unchanged; the decorator replaces the resolved EmbedderService after construction. The config dependency resolves automatically via the container since IndexerConfig is already provided.

func NewGraphRetriever

func NewGraphRetriever(graph repositories.GraphRepository, graphName string, openAICfg config.OpenAIConfig, logger *zap.Logger) services.RetrieverService

func NewGrepRetriever

func NewGrepRetriever(provider services.SourceProvider, root string) services.RetrieverService

NewGrepRetriever creates a retriever that does regex/literal pattern matching on raw files.

func NewHybridRetriever

func NewHybridRetriever(vector, graph services.RetrieverService, alpha float32) services.RetrieverService

func NewIndexerRouter

func NewIndexerRouter(cfg config.IndexerConfig, logger *zap.Logger) services.IndexerService

func NewKeywordRetriever

func NewKeywordRetriever(textRepo repositories.TextSearchRepository, collection string) services.RetrieverService

NewKeywordRetriever creates a BM25-based keyword retriever.

func NewLocalSourceProvider

func NewLocalSourceProvider(cfg config.IndexerConfig) services.SourceProvider

NewLocalSourceProvider creates a SourceProvider backed by the local filesystem.

func NewLocalSourceProviderWithRoot

func NewLocalSourceProviderWithRoot(root string) services.SourceProvider

NewLocalSourceProviderWithRoot creates a SourceProvider with an explicit allowed root.

func NewMerkleService

func NewMerkleService(cfg config.IndexerConfig, envCfg *coreconfig.EnvConfig, logger *zap.Logger) (services.MerkleService, error)

NewMerkleService creates a MerkleService that persists trees to local disk in development, or to S3 in non-development environments.

func NewMultiRetriever

func NewMultiRetriever(
	vector, keyword services.RetrieverService,
	graph repositories.GraphRepository,
	graphName string,
	logger *zap.Logger,
) services.RetrieverService

func NewOpenAIReviewer

func NewOpenAIReviewer(
	apiKey string,
	model string,
	maxTokens int,
	maxTurns int,
	executor *ToolExecutor,
	promptProvider *PromptProvider,
	logger *zap.Logger,
) services.Reviewer

func NewOutboxDispatcher

func NewOutboxDispatcher(
	logger *zap.Logger,
	db *gorm.DB,
	dsn services.PostgresDSN,
	outboxRepo repositories.SyncOutboxRepository,
	asynqClient *asynq.Client,
) services.OutboxDispatcher

NewOutboxDispatcher is the dig provider. Production callers receive a dispatcher backed by a real *asynq.Client and pq.NewListener.

func NewRetriever

func NewRetriever(
	strategy string,
	emb services.EmbedderService,
	store repositories.VectorRepository,
	graph repositories.GraphRepository,
	textRepo repositories.TextSearchRepository,
	provider services.SourceProvider,
	collection string,
	repoRoot string,
	alpha float32,
	openAICfg config.OpenAIConfig,
	logger *zap.Logger,
) services.RetrieverService

NewRetriever builds the appropriate RetrieverService based on the strategy name.

func NewS3SourceProvider

func NewS3SourceProvider(cfg config.IndexerConfig, logger *zap.Logger) (services.SourceProvider, error)

NewS3SourceProvider creates a SourceProvider backed by an S3 bucket using global config.

func NewS3SourceProviderWithParams

func NewS3SourceProviderWithParams(bucket, prefix, region, endpoint string, logger *zap.Logger) (services.SourceProvider, error)

NewS3SourceProviderWithParams creates a SourceProvider backed by an S3 bucket using explicit parameters instead of config. This allows per-request S3 routing. endpoint can be empty for real AWS S3, or a URL like "http://minio:9000" for S3-compatible stores.

func NewSmartChunker

func NewSmartChunker(cfg config.IndexerConfig) *smartChunker

func NewSyncSessionService

NewSyncSessionService wires the dependencies registered in injection/server_container.go. MerkleService is already provided on the server container alongside the indexer providers, and WS4 added dig providers for the SyncBatch/SyncOutbox repos and the typed StreamContentRedisClient.

func NewTreeSitterIndexer

func NewTreeSitterIndexer(cfg config.IndexerConfig, logger *zap.Logger) services.IndexerService

Types

type AnthropicReviewer

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

AnthropicReviewer implements services.Reviewer using the Anthropic Claude API.

func (*AnthropicReviewer) GetMetrics

func (r *AnthropicReviewer) GetMetrics() *services.ReviewMetrics

func (*AnthropicReviewer) Review

type CalleeRef

type CalleeRef struct {
	CallerFile string
	CallerName string
	Name       string
	FilePath   string
	StartLine  int
	EndLine    int
}

CalleeRef points the body-fetcher at a first-hop callee with line range.

type ContractDiff

type ContractDiff struct {
	FilePath     string
	Function     string
	OldSignature string
	NewSignature string
	Changes      []string // "params", "return_type", "modifiers"
}

ContractDiff captures a same-named function's signature change. Body-only edits never appear here.

type DiffIndex

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

DiffIndex summarizes a unified diff as per-file maps from new-side line numbers to line content. Only commentable lines (added `+` and context ` ` on the new side) are indexed; deleted lines are excluded.

func (*DiffIndex) Content

func (d *DiffIndex) Content(file string, line int32) string

Content returns the content of the commentable line, stripped of the unified-diff prefix. Returns "" if the line is not indexed.

func (*DiffIndex) IsValidLine

func (d *DiffIndex) IsValidLine(file string, line int32) bool

IsValidLine reports whether line is a commentable new-side line for file.

func (*DiffIndex) Nearby

func (d *DiffIndex) Nearby(file string, line, window int32) map[int32]string

Nearby returns all commentable (line, content) pairs for file within [line-window, line+window].

type GraphContext

type GraphContext struct {
	CallerMap         map[string][]string
	CalleeRefs        []CalleeRef
	Importers         []string
	Formatted         string
	FunctionsAnalyzed int
	CallersFound      int
	CalleesFound      int
}

GraphContext holds pre-assembled callers, callees, and importer paths for changed code.

func AssembleGraphContext

func AssembleGraphContext(
	ctx context.Context,
	graph repositories.GraphRepository,
	collectionName string,
	files []services.PRFileInfo,
	contractDiffs []ContractDiff,
	filter services.SearchFilter,
	logger *zap.Logger,
) *GraphContext

AssembleGraphContext renders a dense, risk-sorted prompt block of callers and contract changes.

type IndexRetrievalServiceImpl

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

func (*IndexRetrievalServiceImpl) DeleteIndex

func (*IndexRetrievalServiceImpl) GetContext

func (*IndexRetrievalServiceImpl) GetIndexStatus

func (s *IndexRetrievalServiceImpl) GetIndexStatus(ctx context.Context, repoPath, userID string, workspaceID uint64, machineID string) (*dto.IndexStatusResponse, error)

func (*IndexRetrievalServiceImpl) GraphQuery

func (*IndexRetrievalServiceImpl) Search

func (*IndexRetrievalServiceImpl) TriggerIndex

func (s *IndexRetrievalServiceImpl) TriggerIndex(ctx context.Context, req *dto.IndexRequest) (string, error)

type OpenAIReviewer

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

OpenAIReviewer implements services.Reviewer using the OpenAI Responses API.

func (*OpenAIReviewer) GetMetrics

func (r *OpenAIReviewer) GetMetrics() *services.ReviewMetrics

func (*OpenAIReviewer) Review

type PRClassification

type PRClassification int

PRClassification determines how a PR should be reviewed.

const (
	// PRSkip means no AI review needed (docs, lockfiles, CI config).
	PRSkip PRClassification = iota
	// PRTrivial means a cheap fast review (config, test-only, small changes).
	PRTrivial
	// PRStandard means a normal review with graph context.
	PRStandard
)

func ClassifyPR

func ClassifyPR(files []services.PRFileInfo) (PRClassification, string)

ClassifyPR determines the review classification for a PR based on its files. This is the gatekeeper — it runs before any LLM call.

func (PRClassification) String

func (c PRClassification) String() string

type Pipeline

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

func (*Pipeline) Analyze

func (p *Pipeline) Analyze(ctx context.Context, repoPath string, indexReq *dto.IndexRequest) (*services.ReviewOutput, *services.ReviewMetrics, error)

func (*Pipeline) Index

func (p *Pipeline) Index(ctx context.Context, req *dto.IndexRequest) error

Index is the legacy repo-level entry point used by /index/trigger and codereview. It resolves the collection, builds a fresh Merkle tree from the source provider, diffs it against the stored tree, and delegates the actual indexing work to IndexChangedFiles. The Merkle tree is saved only when the delegate reports zero per-file failures (Delta A in the WS2 plan) so any failed files are automatically retried on the next Index call.

func (*Pipeline) IndexChangedFiles

func (p *Pipeline) IndexChangedFiles(
	ctx context.Context,
	collectionName string,
	indexRoot string,
	identity services.IndexIdentity,
	provider services.SourceProvider,
	changedFiles []string,
	deletedFiles []string,
) (*services.IndexStats, error)

IndexChangedFiles indexes exactly the specified files and removes the specified paths from Qdrant, FalkorDB, and the text store. It does NOT touch the Merkle tree, resolve the collection name, or decide which files are "changed" — all of that is the caller's responsibility.

Contract (see services/pipeline_identity.go for the full description):

return (stats, nil) → batch reached a commit-worthy state; streaming
                      workers call markBatchProcessed(stats).
return (nil,   err) → whole-batch failure. TerminalError wraps errors
                      that must not be retried (markBatchTerminallyFailed
                      via the durable manifest); ordinary errors bubble
                      up for Asynq retry.
never (stats, err)  → forbidden; would double-account.

Callers supplying an InMemorySourceProvider MUST pass indexRoot="". The legacy Pipeline.Index wrapper passes req.RepoPath (or "" for S3) to match the pre-refactor behavior.

func (*Pipeline) IsCollectionPopulated

func (p *Pipeline) IsCollectionPopulated(ctx context.Context, req *dto.IndexRequest) bool

IsCollectionPopulated reports whether the repo's vector collection has any points. Errors are treated as cold so the caller falls into the sync-index path rather than running a review without context.

func (*Pipeline) Review

type PromptProvider

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

PromptProvider provides prompt templates via compile-time embedded text files.

func NewPromptProvider

func NewPromptProvider() *PromptProvider

func (*PromptProvider) Audit

func (p *PromptProvider) Audit() string

func (*PromptProvider) MaxTurns

func (p *PromptProvider) MaxTurns() string

func (*PromptProvider) SystemReview

func (p *PromptProvider) SystemReview() string

type RiskAssessment

type RiskAssessment struct {
	Level   string
	Score   float64
	Reason  string
	Factors []services.RiskFactor
}

RiskAssessment is the deterministic structural-risk output.

type ShardBootstrap

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

func NewShardBootstrap

func NewShardBootstrap(
	shardCfg config.ShardConfig,
	openAICfg config.OpenAIConfig,
	store repositories.VectorRepository,
	logger *zap.Logger,
) *ShardBootstrap

func (*ShardBootstrap) Bootstrap

func (b *ShardBootstrap) Bootstrap(ctx context.Context) error

type ToolExecutor

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

func NewToolExecutor

func NewToolExecutor(
	ret services.RetrieverService,
	graph repositories.GraphRepository,
	repoPath string,
	collectionName string,
	filter services.SearchFilter,
	logger *zap.Logger,
) *ToolExecutor

func (*ToolExecutor) Execute

func (e *ToolExecutor) Execute(ctx context.Context, toolName string, input []byte) (string, error)

func (*ToolExecutor) HasBackend

func (e *ToolExecutor) HasBackend() bool

func (*ToolExecutor) SetMetrics

func (e *ToolExecutor) SetMetrics(m *services.ReviewMetrics)

Jump to

Keyboard shortcuts

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