Skip to content

CU-86exuferc: AI Review Engine — LLM Integration#3

Merged
miqdadyyy merged 3 commits into
mainfrom
feature/CU-86exuferc-ai-review-engine-llm-integration
Jun 4, 2026
Merged

CU-86exuferc: AI Review Engine — LLM Integration#3
miqdadyyy merged 3 commits into
mainfrom
feature/CU-86exuferc-ai-review-engine-llm-integration

Conversation

@miqdadyyy

Copy link
Copy Markdown
Owner

Summary

Implements the core AI review engine that sends code diffs to configured LLM providers and returns structured review feedback. Reuses the existing encrypted provider domain for AI credentials and mirrors the established services/vcs factory pattern for services/llm.

ClickUp Ticket

Changes

LLM service layer (internal/services/llm/)

  • ILLMFactory + ILLMService interfaces mirroring services/vcs.
  • OpenAI-compatible client (works with any OpenAI proxy: LiteLLM, vLLM, Ollama, Azure OpenAI), Anthropic client, and custom proxy client.
  • Shared base.go HTTP helper (Fiber client) with exponential-backoff retry and upstream status mapping.
  • Streaming support via StreamComplete.

AI provider integration (reuses provider domain)

  • New constants: ProviderCategoryAI, ProviderTypeOpenAI/Anthropic/Custom, ProviderAuthModeAPIKey.
  • ProviderAIMetadata (api key / base URL / model) stored via the existing AES-encrypted EncryptedField — keys never stored in plaintext.

AI connector CRUD (internal/usecase/aiconnector/)

  • POST/GET/PUT/DELETE /api/v1/connectors.
  • API keys are masked in all responses (****<last4>).

Review engine (internal/usecase/review/)

  • POST /api/v1/reviews/diff: orchestrates diff → prompt → LLM → parsed ReviewComment list.
  • System + user prompt template system; DB-stored, per-repo editable templates (aiprompttemplate repo domain, AutoMigrate).
  • Robust JSON extraction from model output; token counting + cost estimation.

Wiring & config

  • New repo/usecase/service constructors added to cmd/cli/wire.go (regenerated wire_gen.go).
  • LLMConfig added to config entity and config/local.yaml.

Testing

  • go build ./... — success
  • go test ./...245 passed (incl. new table-driven tests for aiconnector and review usecases covering success, not-found, wrapped-error, and JSON-parse-failure paths)
  • make lint0 issues
  • gofmt clean on all changed files

Acceptance Criteria

  • Configure OpenAI, Anthropic, or custom LLM endpoint
  • Sending a diff chunk returns structured review comments
  • Supports any OpenAI-compatible proxy (LiteLLM, vLLM, Ollama, etc.)
  • API keys are never exposed in responses

Note

This repo has no develop branch; the branch was created from feat/ai-provider (not yet on remote) per request. PR is targeted at mainretarget to the intended integration branch before merge if needed.

Add the core AI review engine that sends code diffs to configured LLM
providers and returns structured review feedback.

- Add ai/openai/anthropic/custom provider types reusing the encrypted
  provider domain so API keys are stored encrypted and never returned
  in full (masked in responses).
- Add internal/services/llm: ILLMFactory + ILLMService with
  OpenAI-compatible (LiteLLM/vLLM/Ollama/Azure), Anthropic, and custom
  proxy clients, shared HTTP helper with exponential backoff retry.
- Add ai_connector usecase: CRUD endpoints at /api/v1/connectors.
- Add review usecase: orchestrates diff -> prompt -> LLM -> parsed
  ReviewComment list with prompt templates, token counting and cost
  estimation; POST /api/v1/reviews/diff.
- Add aiprompttemplate repository domain (DB-stored, per-repo editable
  prompts) registered in AutoMigrate.
- Wire new repos/usecases/services; add LLMConfig; table-driven tests.
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown

✅ Coverage Report

Metric Value
Total Coverage 70.5%
Threshold 60.0%
Status Passed

@miqdadyyy miqdadyyy left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So basically the AI review workflow is not correct yet
It should be handled under worker / background nats process
The usecase and several code already correct, but the coverage doesn't meet the requirement

Comment thread internal/handler/http/review.go Outdated
Comment thread internal/services/llm/implementation/anthropic.go Outdated
Comment thread internal/services/llm/implementation/anthropic.go Outdated
Comment thread internal/services/llm/implementation/openai.go Outdated
Comment thread internal/services/llm/implementation/openai.go Outdated
Comment thread internal/services/llm/models/llm.go
Comment thread internal/usecase/aiconnector/implementation/ai_connector.go Outdated
- Run AI review as a background NATS worker job: HTTP POST
  /api/v1/reviews/diff now enqueues via IPubSub and returns 202
  Accepted; new worker HandleReviewDiff consumes the job and runs the
  LLM review. Adds review_diff topic/channel constants and subscription.
- Move provider request/response structs out of the implementation
  package into internal/services/llm/models/{openai,anthropic}.go.
- Move shared helpers (firstNonEmptyStr, firstAnthropicText, emitStream)
  into base.go; rename models/models.go to llm.go.
- Replace 'validation failed' literal with fiber.ErrUnprocessableEntity
  .Error() across all HTTP handlers.
- Replace hand-rolled maskSecret with a reflection-based
  internal/pkg/mask package driven by mask:"start=N"/mask:"end=N"
  struct tags; ConnectorResponse.APIKey now masked declaratively.
- Expand test coverage: mask pkg, llm openai/anthropic via httptest,
  llm factory, worker handler, aiconnector List/Update, review
  Enqueue + prompt-template path (275 tests pass, lint clean).
@miqdadyyy

Copy link
Copy Markdown
Owner Author

Thanks for the review — all points addressed in the latest commit (4fad062b4ad4c29b81435b74c86cd9438e2d9748):

Architecture: background worker

  • POST /api/v1/reviews/diff now enqueues the job via IPubSub and returns 202 Accepted with a job id.
  • New worker handler HandleReviewDiff (internal/handler/worker/review.go) consumes review_diff_topic and runs the LLM review under the NATS worker process (subscribed in cmd/cli/runner/worker.go with concurrency 5).

Inline comments

  • review.go validation message → now uses fiber.ErrUnprocessableEntity.Error() (applied to all handlers for consistency).
  • OpenAI structs → moved to internal/services/llm/models/openai.go.
  • Anthropic structs → moved to internal/services/llm/models/anthropic.go.
  • firstTextBlock/firstNonEmptyStr (+ emitStream) → moved into base.go.
  • models/models.go → renamed to llm.go.
  • maskSecret removed → replaced by reflection-based internal/pkg/mask package driven by mask:"start=N" / mask:"end=N" struct tags. ConnectorResponse.APIKey is now masked declaratively (e.g. ******1234).

Coverage
Added tests: mask pkg (97%), llm openai/anthropic via httptest + factory, worker handler (100%), aiconnector List/Update, review Enqueue + prompt-template path. Full suite: 275 passed, make lint 0 issues.

@miqdadyyy
miqdadyyy merged commit 3c4fa2a into main Jun 4, 2026
2 checks passed
@miqdadyyy
miqdadyyy deleted the feature/CU-86exuferc-ai-review-engine-llm-integration branch June 8, 2026 03:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant