From 5a829683459011f6f0f6c53b9f3bf7601b2d6468 Mon Sep 17 00:00:00 2001 From: shaj13 Date: Sun, 5 Apr 2026 15:55:59 +0000 Subject: [PATCH] rag/treesitter: add nocgo build support Allow building without CGO for applications that do not use RAG. DocumentProcessor returns an error when built without CGO and RAG is used. --- pkg/rag/treesitter/treesitter.go | 2 ++ pkg/rag/treesitter/treesitter_nocgo.go | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 pkg/rag/treesitter/treesitter_nocgo.go diff --git a/pkg/rag/treesitter/treesitter.go b/pkg/rag/treesitter/treesitter.go index cb7d6d82e..02dc26830 100644 --- a/pkg/rag/treesitter/treesitter.go +++ b/pkg/rag/treesitter/treesitter.go @@ -1,3 +1,5 @@ +//go:build cgo + package treesitter import ( diff --git a/pkg/rag/treesitter/treesitter_nocgo.go b/pkg/rag/treesitter/treesitter_nocgo.go new file mode 100644 index 000000000..1dacaa937 --- /dev/null +++ b/pkg/rag/treesitter/treesitter_nocgo.go @@ -0,0 +1,24 @@ +//go:build !cgo + +package treesitter + +import ( + "errors" + + "github.com/docker/docker-agent/pkg/rag/chunk" +) + +// DocumentProcessor implements chunk.DocumentProcessor and always returns an +// error when the application is built without CGO and uses RAG. For applications +// that do not use RAG, this allows building without any CGO requirement. +type DocumentProcessor struct{} + +// NewDocumentProcessor creates a new DocumentProcessor. +func NewDocumentProcessor(_, _ int, _ bool) *DocumentProcessor { + return &DocumentProcessor{} +} + +// Process implements chunk.DocumentProcessor. +func (p *DocumentProcessor) Process(_ string, _ []byte) ([]chunk.Chunk, error) { + return nil, errors.New("rag/treesitter: document processor must be built with CGO_ENABLED=1") +}