2026-02-19 21:34:55 +00:00
# CLAUDE.md
2026-03-13 13:38:01 +00:00
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
2026-02-19 21:34:55 +00:00
## Project Overview
2026-03-13 13:38:01 +00:00
**go-ai** is a thin facade layer in the Lethean AI stack. After a March 2026 refactor, the MCP server and all 49 tools were extracted to `forge.lthn.ai/core/mcp` . What remains here is the AI metrics system, a RAG query wrapper, and CLI command wrappers that delegate to other modules.
2026-02-19 21:34:55 +00:00
2026-03-21 23:52:57 +00:00
- **Module path**: `dappco.re/go/core/ai`
2026-03-13 13:38:01 +00:00
- **Language**: Go 1.26
2026-02-19 21:34:55 +00:00
- **Licence**: EUPL-1.2
## Build & Test Commands
```bash
2026-03-21 23:52:57 +00:00
go build dappco.re/go/core/ai/... # Build (library — no main package)
go test dappco.re/go/core/ai/... # Run all tests
go test -run TestName dappco.re/go/core/ai/ai # Run a single test
go test -v -race dappco.re/go/core/ai/... # Verbose with race detector
go test -bench=. dappco.re/go/core/ai/ai # Run benchmarks (metrics)
go vet dappco.re/go/core/ai/... # Vet
fix(ai): DX audit — update CLAUDE.md, add tests, fix io consistency
- CLAUDE.md: remove deleted daemon/ entry, add embed-bench/ and lab/,
fix build commands for go workspace (./... → module path),
update error handling guidance to coreerr.E(), remove stale
cli.AddDaemonCommand reference
- Replace os.MkdirAll with coreio.Local.EnsureDir in bench/test code
- Add 14 unit tests for metrics (Record, ReadEvents, Summary, sortedMap,
readMetricsFile edge cases) — ai/ coverage 65.3% → 67.3%
- Add parseDuration tests for cmd/metrics — coverage 0% → 24.6%
- No fmt.Errorf or errors.New violations found
- No os.ReadFile/os.WriteFile violations found
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-17 08:01:21 +00:00
golangci-lint run ./... # Lint (from module root)
2026-02-19 21:34:55 +00:00
```
2026-03-13 13:38:01 +00:00
## Architecture
### `ai/` — Core facade package
Two concerns, no external service calls at import time:
1. **Metrics** (`metrics.go` ) — Append-only JSONL event storage at `~/.core/ai/metrics/YYYY-MM-DD.jsonl` . Thread-safe via `sync.Mutex` . Key functions: `Record(Event)` , `ReadEvents(since)` , `Summary([]Event)` .
2026-04-01 05:58:24 +00:00
2. **RAG** (`rag.go` ) — `QueryRAGForTask(TaskInfo)` wraps `go-rag` to query Qdrant for documentation context. Truncates to 500 runes, returns top-3 results above 0.5 threshold. Returns an empty string on failure for graceful degradation at call sites.
2026-03-13 13:38:01 +00:00
### `cmd/` — CLI command wrappers
Each subpackage exposes an `Add*Command(root)` function that registers cobra commands. They delegate to other modules:
| Subpackage | Delegates to |
|---|---|
fix(ai): DX audit — update CLAUDE.md, add tests, fix io consistency
- CLAUDE.md: remove deleted daemon/ entry, add embed-bench/ and lab/,
fix build commands for go workspace (./... → module path),
update error handling guidance to coreerr.E(), remove stale
cli.AddDaemonCommand reference
- Replace os.MkdirAll with coreio.Local.EnsureDir in bench/test code
- Add 14 unit tests for metrics (Record, ReadEvents, Summary, sortedMap,
readMetricsFile edge cases) — ai/ coverage 65.3% → 67.3%
- Add parseDuration tests for cmd/metrics — coverage 0% → 24.6%
- No fmt.Errorf or errors.New violations found
- No os.ReadFile/os.WriteFile violations found
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-17 08:01:21 +00:00
| `embed-bench/` | Ollama API — embedding model benchmarking tool |
| `lab/` | `forge.lthn.ai/lthn/lem/pkg/lab` — homelab monitoring dashboard |
2026-03-13 13:38:01 +00:00
| `metrics/` | `ai.ReadEvents()` / `ai.Summary()` |
| `rag/` | `forge.lthn.ai/core/go-rag/cmd/rag` (re-export) |
| `security/` | GitHub API via `gh` CLI (alerts, deps, secrets, scanning) |
### Key sibling modules
The MCP server and tools live in separate modules. When working on tool registration or transport, you need `core/mcp` , not this repo.
- `forge.lthn.ai/core/mcp` — MCP server, transports, tool registration, IDE bridge
- `forge.lthn.ai/core/go-rag` — Qdrant vector DB + Ollama embeddings
- `forge.lthn.ai/core/go-ml` — Scoring engine, heuristics, probes
- `forge.lthn.ai/core/go-inference` — Shared ML backend interfaces
fix(ai): DX audit — update CLAUDE.md, add tests, fix io consistency
- CLAUDE.md: remove deleted daemon/ entry, add embed-bench/ and lab/,
fix build commands for go workspace (./... → module path),
update error handling guidance to coreerr.E(), remove stale
cli.AddDaemonCommand reference
- Replace os.MkdirAll with coreio.Local.EnsureDir in bench/test code
- Add 14 unit tests for metrics (Record, ReadEvents, Summary, sortedMap,
readMetricsFile edge cases) — ai/ coverage 65.3% → 67.3%
- Add parseDuration tests for cmd/metrics — coverage 0% → 24.6%
- No fmt.Errorf or errors.New violations found
- No os.ReadFile/os.WriteFile violations found
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-17 08:01:21 +00:00
- `forge.lthn.ai/core/cli` — CLI framework (`cli.Command` , command registration)
2026-03-13 13:38:01 +00:00
- `forge.lthn.ai/core/go-i18n` — Internationalisation strings
2026-02-19 21:34:55 +00:00
## Coding Standards
- **UK English** in comments and user-facing strings (colour, organisation, centre)
- **Conventional commits**: `type(scope): description`
- **Co-Author**: `Co-Authored-By: Virgil <virgil@lethean.io>`
fix(ai): DX audit — update CLAUDE.md, add tests, fix io consistency
- CLAUDE.md: remove deleted daemon/ entry, add embed-bench/ and lab/,
fix build commands for go workspace (./... → module path),
update error handling guidance to coreerr.E(), remove stale
cli.AddDaemonCommand reference
- Replace os.MkdirAll with coreio.Local.EnsureDir in bench/test code
- Add 14 unit tests for metrics (Record, ReadEvents, Summary, sortedMap,
readMetricsFile edge cases) — ai/ coverage 65.3% → 67.3%
- Add parseDuration tests for cmd/metrics — coverage 0% → 24.6%
- No fmt.Errorf or errors.New violations found
- No os.ReadFile/os.WriteFile violations found
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-17 08:01:21 +00:00
- **Error handling**: Use `coreerr.E("pkg.Func", "what failed", err)` from `go-log` , never `fmt.Errorf` or panic
2026-03-13 13:38:01 +00:00
- **Test naming**: `TestFoo_Good` (happy path), `TestFoo_Bad` (expected errors), `TestFoo_Ugly` (panics/edge cases)
- **Licence**: EUPL-1.2 (SPDX header on new files)