Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Trivy filesystem scan
uses: aquasecurity/trivy-action@0.28.0
uses: aquasecurity/trivy-action@v0.36.0
with:
scan-type: fs
ignore-unfixed: true
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,6 @@ cython_debug/
*.test
*.out
coverage.txt

# benchmark run output (results summarized in docs/PR, not tracked)
deploy/eval-containers/sweep-results.csv
34 changes: 19 additions & 15 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
# CLAUDE.md

Guidance for working in `lab-context-engineering`, a Kagenti platform component.
Guidance for working in `context-guru` (repo dir `lab-context-engineering`), a Kagenti
platform component.

## What this repo is

A single **Go** core that reduces the token cost of LLM agent traffic. It ships as a
standalone proxy binary (`cmd/proxy`), an importable library (`engine`, `surfaces`), and
eval-containers wiring. Its lineage is the Python `winnow` prototype (`../winnow`), which
is the behavioral reference — port its *logic*, re-implement its transport in Go.
A single **Go** core (`components`) that reduces the token cost of LLM agent traffic,
operating on bifrost's provider-agnostic chat schema. It ships as a proxy binary
(`cmd/context-guru-proxy`), an importable library (`components`, `apply`, `schema`,
`config`, `expand`, `store`), a bifrost `LLMPlugin` adapter (`adapters/bifrost`), and
eval-containers wiring. Its lineage is the Python `winnow` prototype, the behavioral
reference — port its *logic*, re-implement its transport in Go.

## Hard boundaries

- **No AuthBridge / kagenti-extensions code lives here.** That plugin is built in
`kagenti-extensions` and depends on this repo. Keep the public API (`engine`,
`surfaces`, `config`) clean and importable; never reach into another repo.
- **Fail open, always.** Any error in any compactor forwards the original request untouched.
Reductions must be reversible (markers + rewind store). Never drop content that is only
*predicted* unused — `provable_only` is on by default.
`kagenti-extensions` and depends on this repo. Keep the public API (`components`,
`apply`, `schema`, `config`) clean and importable; never reach into another repo.
- **Fail open, always.** Any component error/panic reverts that component only; the
original request is always forwarded as a valid fallback. Every lossy Offload must be
reversible (a `<<cg:HASH>>` marker + the stashed original in the Store).

## Conventions

- Go 1.25, module `github.com/kagenti/lab-context-engineering`. `make fmt lint test build`.
- Go 1.26, module `github.com/kagenti/context-guru`. Build needs `CGO_ENABLED=1` (tree-sitter).
- Match the surrounding code's style; keep packages small and single-purpose.
- **Commits: DCO sign-off is mandatory** — `git commit -s`. Author as the repo owner.
AI attribution uses `Assisted-By:` — never `Co-Authored-By`, never a "Generated with"
Expand All @@ -29,7 +32,8 @@ is the behavioral reference — port its *logic*, re-implement its transport in

## Layout

`cmd/proxy` (binary) · `engine` (Transform/Expand + Compactor pipeline) · `surfaces` (wire⇄canonical)
· `internal/*` (types, extract, relevance, signals, taxonomy, actions, cache, markers,
rewind, zones, session, compaction, tokens) · `config` · `observability` · `deploy` ·
`docs`.
`components` (Component/Reformat/Offload + Pipeline + registry) · `components/{reformat,offload,dsl,all}`
· `apply` (wire body ⇄ pipeline, byte-lossless splice) · `schema` (bifrost-schema helpers) ·
`expand` (marker + expand tool loop) · `store` · `session` · `metrics` · `config` ·
`proxy` · `adapters/bifrost` · `cmd/context-guru-proxy` · `internal/{tokens,treesitter,buildinfo}`
· `deploy` · `docs`. See [docs/design.md](docs/design.md).
41 changes: 30 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
# Build the lab-cx proxy. CGO is required (tree-sitter), so the final image is
# glibc-based (distroless/base), not static.
FROM golang:1.25 AS build
# context-guru-proxy: the LLM-proxy integration and eval-containers gateway.
#
# The module uses a local `replace github.com/maximhq/bifrost/core => ../bifrost/core`,
# so the build context MUST be the PARENT directory that contains both repos:
#
# docker build -f lab-context-engineering/Dockerfile -t context-guru-proxy .
#
# (run from .../context-engineering/). CI that builds standalone should either
# `go mod vendor` first or switch the replace to a pinned published bifrost.
#
# CGO is required (tree-sitter for the skeleton component), so the final image is
# glibc-based. It also carries a shell + curl for the eval-containers
# start/health scripts under /opt/gateway.
FROM golang:1.26 AS build
WORKDIR /src
COPY . .
COPY bifrost/ ./bifrost/
COPY lab-context-engineering/ ./lab-context-engineering/
WORKDIR /src/lab-context-engineering
ARG VERSION=dev
ARG COMMIT=none
RUN CGO_ENABLED=1 go build \
-ldflags "-s -w -X github.com/kagenti/lab-context-engineering/internal/buildinfo.Version=${VERSION} -X github.com/kagenti/lab-context-engineering/internal/buildinfo.Commit=${COMMIT}" \
-o /out/lab-cx ./cmd/proxy
-ldflags "-s -w -X github.com/kagenti/context-guru/internal/buildinfo.Version=${VERSION} -X github.com/kagenti/context-guru/internal/buildinfo.Commit=${COMMIT}" \
-o /out/context-guru-proxy ./cmd/context-guru-proxy

FROM gcr.io/distroless/base-debian12:nonroot
COPY --from=build /out/lab-cx /usr/local/bin/lab-cx
EXPOSE 8080
ENTRYPOINT ["/usr/local/bin/lab-cx"]
CMD ["proxy"]
FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl \
&& rm -rf /var/lib/apt/lists/*
COPY --from=build /out/context-guru-proxy /opt/gateway/main
COPY lab-context-engineering/deploy/eval-containers/start /opt/gateway/start
COPY lab-context-engineering/deploy/eval-containers/health /opt/gateway/health
RUN chmod +x /opt/gateway/start /opt/gateway/health
EXPOSE 4000
# Default entrypoint is the eval-containers gateway wrapper; override with
# `/opt/gateway/main` to run the proxy directly with flags.
ENTRYPOINT ["/opt/gateway/start"]
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BINARY := lab-cx
PKG := github.com/kagenti/lab-context-engineering
BINARY := context-guru-proxy
PKG := github.com/kagenti/context-guru
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo none)
LDFLAGS := -s -w \
Expand All @@ -18,9 +18,9 @@ help: ## Display this help
awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-12s\033[0m %s\n", $$1, $$2}'

.PHONY: build
build: ## Build the lab-cx binary into ./bin
build: ## Build the context-guru-proxy binary into ./bin
@mkdir -p bin
go build -ldflags "$(LDFLAGS)" -o bin/$(BINARY) ./cmd/proxy
go build -ldflags "$(LDFLAGS)" -o bin/$(BINARY) ./cmd/context-guru-proxy

.PHONY: test
test: ## Run all tests with the race detector
Expand Down
Loading
Loading