|
| 1 | +# Keep v1.0.0 Design |
| 2 | + |
| 3 | +**Date:** 2026-04-03 |
| 4 | +**Status:** Approved |
| 5 | +**Goal:** Public open-source release with semver stability guarantees |
| 6 | + |
| 7 | +## Context |
| 8 | + |
| 9 | +Keep is at v0.2.0 with all core components implemented: CEL-based policy engine, YAML rule files, MCP relay, LLM gateway, CLI, Go library API, and Anthropic codec. The codebase has 56 test files with 66-100% coverage across packages, comprehensive documentation, and production features (graceful shutdown, hot reload, streaming, secret detection, rate limiting). |
| 10 | + |
| 11 | +v1.0.0 graduates Keep to a public release. The public Go API surface, rule file format, CLI interface, and config schemas all become semver-stable contracts. Breaking changes are acceptable before 1.0 but not after. |
| 12 | + |
| 13 | +## Positioning |
| 14 | + |
| 15 | +Keep is a standalone library and set of small composable tools. Moat is the flagship deployment context, but Keep works independently — someone with no Moat context can install it, write rules, and run it. |
| 16 | + |
| 17 | +## What Ships in v1.0.0 |
| 18 | + |
| 19 | +### 1. New Provider Codecs |
| 20 | + |
| 21 | +**OpenAI/Codex codec (`llm/openai/`)** |
| 22 | + |
| 23 | +Implements the existing `llm.Codec` interface for the OpenAI Chat Completions API. |
| 24 | + |
| 25 | +- Decomposes requests/responses into `keep.Call` objects |
| 26 | +- Content block types: `tool_use`, `tool_result`, `text`, `image_url` |
| 27 | +- Streaming support via SSE (same pattern as Anthropic codec) |
| 28 | +- Function calling (legacy) mapped to `tool_use` canonical form |
| 29 | +- Gateway gains `provider: openai` config option |
| 30 | + |
| 31 | +**Gemini codec (`llm/gemini/`)** |
| 32 | + |
| 33 | +Implements `llm.Codec` for the Gemini `generateContent` API. |
| 34 | + |
| 35 | +- Decomposes requests/responses into `keep.Call` objects |
| 36 | +- Part types: `functionCall`, `functionResponse`, `text`, `inlineData` |
| 37 | +- Streaming via Gemini's SSE format |
| 38 | +- Gateway gains `provider: gemini` config option |
| 39 | + |
| 40 | +**Design principle:** Each codec is a self-contained package. No shared base class — just the `Codec` interface. Provider-specific types stay in their own package (e.g., `openai.Request`, `gemini.Part`). |
| 41 | + |
| 42 | +### 2. Canonical Operation Taxonomy |
| 43 | + |
| 44 | +A normalization layer that maps provider-specific operation names to canonical names, so rules can be written once and match across providers and MCP servers. |
| 45 | + |
| 46 | +**Canonical categories:** |
| 47 | + |
| 48 | +| Category | Canonical Operations | |
| 49 | +|----------|---------------------| |
| 50 | +| `file` | `file.read`, `file.write`, `file.list`, `file.delete` | |
| 51 | +| `code` | `code.execute`, `code.analyze` | |
| 52 | +| `net` | `net.http`, `net.dns`, `net.connect` | |
| 53 | +| `data` | `data.query`, `data.mutate`, `data.schema` | |
| 54 | +| `msg` | `msg.send`, `msg.read`, `msg.list` | |
| 55 | +| `auth` | `auth.token`, `auth.credential` | |
| 56 | +| `shell` | `shell.exec`, `shell.spawn` | |
| 57 | + |
| 58 | +This is a starting vocabulary, not a closed set. New canonical names can be added in 1.x without breaking changes. The taxonomy is intentionally shallow (two levels) to stay learnable. |
| 59 | + |
| 60 | +**How mapping works:** |
| 61 | + |
| 62 | +```yaml |
| 63 | +# Built-in mappings ship with each codec and relay |
| 64 | +# Users can extend/override in rule files |
| 65 | +normalize: |
| 66 | + mappings: |
| 67 | + read_file: file.read |
| 68 | + readFile: file.read |
| 69 | + ReadFileTool: file.read |
| 70 | + execute_command: shell.exec |
| 71 | + run_bash: shell.exec |
| 72 | +``` |
| 73 | +
|
| 74 | +**Rule matching behavior:** |
| 75 | +
|
| 76 | +- Rules can use raw names (`read_file`) or canonical names (`file.read`) |
| 77 | +- When `normalize: true` on a scope, the engine checks both the raw and canonical name |
| 78 | +- No forced migration — existing rules continue to work untouched |
| 79 | +- Canonical names in rules match any raw name that maps to them |
| 80 | + |
| 81 | +**Where mappings live:** |
| 82 | + |
| 83 | +- Built-in defaults ship per codec/provider (e.g., common MCP server tools, Anthropic computer-use tools) |
| 84 | +- User-defined mappings in rule files override built-ins |
| 85 | +- The CLI `keep validate` warns on unmapped operations (info-level, not error) |
| 86 | + |
| 87 | +### 3. API Surface Audit & Cleanup |
| 88 | + |
| 89 | +Review and finalize all public API before stability guarantee. |
| 90 | + |
| 91 | +**`keep.go` top-level API:** |
| 92 | + |
| 93 | +- Audit exported types: `Engine`, `Call`, `Decision`, `Mutation`, `AuditEntry`, `RuleSet` |
| 94 | +- Audit exported functions: `Load`, `LoadFromBytes`, `Evaluate`, `Reload`, `ApplyMutations`, `ValidateRuleBytes` |
| 95 | +- Review option types: `WithAuditHook`, `WithRateStore` |
| 96 | +- Ensure naming consistency across the surface |
| 97 | +- Remove anything experimental or under-baked |
| 98 | + |
| 99 | +**`llm/` package API:** |
| 100 | + |
| 101 | +- `Codec` interface — review method signatures |
| 102 | +- `EvaluateRequest`, `EvaluateResponse`, `EvaluateStream` — confirm naming and error semantics |
| 103 | +- `DecomposeConfig` — review fields |
| 104 | + |
| 105 | +**Rule file format:** |
| 106 | + |
| 107 | +- Lock down YAML schema: scopes, rules, actions, when expressions, normalize block |
| 108 | +- Document what's stable vs experimental |
| 109 | +- Version field in rule files (default `v1`, future-proofing) |
| 110 | + |
| 111 | +**Config formats:** |
| 112 | + |
| 113 | +- `relay.yaml` schema finalized |
| 114 | +- `gateway.yaml` schema finalized (with new `provider` options) |
| 115 | + |
| 116 | +**CLI interface:** |
| 117 | + |
| 118 | +- `keep validate` and `keep test` — stable |
| 119 | +- `keep normalize` (new) — show canonical mappings for a rule set |
| 120 | +- Version output includes build metadata |
| 121 | + |
| 122 | +### 4. Distribution & Packaging |
| 123 | + |
| 124 | +**Tagged releases:** |
| 125 | + |
| 126 | +- Semver tags (`v1.0.0`) on the Go module |
| 127 | +- GitHub Releases with changelogs and pre-built binaries (linux/amd64, linux/arm64, darwin/amd64, darwin/arm64) |
| 128 | + |
| 129 | +**Homebrew:** |
| 130 | + |
| 131 | +- Formula for `keep`, `keep-mcp-relay`, `keep-llm-gateway` |
| 132 | +- Tap at `majorcontext/tap` (or similar) |
| 133 | + |
| 134 | +**Container images:** |
| 135 | + |
| 136 | +- `ghcr.io/majorcontext/keep-mcp-relay` |
| 137 | +- `ghcr.io/majorcontext/keep-llm-gateway` |
| 138 | +- Minimal distroless base images |
| 139 | +- Multi-arch (amd64, arm64) |
| 140 | + |
| 141 | +**Go module:** |
| 142 | + |
| 143 | +- Clean `go.mod` with stable dependencies |
| 144 | +- Module path finalized (currently `keep` — may need full path like `github.com/majorcontext/keep`) |
| 145 | + |
| 146 | +### 5. Documentation for Public Audience |
| 147 | + |
| 148 | +**Reframe existing docs:** |
| 149 | + |
| 150 | +- Introduction positions Keep as standalone, mentions Moat as flagship deployment |
| 151 | +- Installation covers all distribution methods |
| 152 | +- Quick start works without Moat context |
| 153 | + |
| 154 | +**New docs needed:** |
| 155 | + |
| 156 | +- Multi-provider guide (writing rules that work across Anthropic/OpenAI/Gemini) |
| 157 | +- Normalization guide (canonical operations, custom mappings) |
| 158 | +- Migration guide (v0.2 → v1.0 breaking changes) |
| 159 | +- CHANGELOG for the v1.0.0 release |
| 160 | + |
| 161 | +**Existing docs refresh:** |
| 162 | + |
| 163 | +- LLM Gateway guide updated for OpenAI and Gemini providers |
| 164 | +- CEL Functions reference updated if normalization adds new functions |
| 165 | +- Rule File reference updated with `normalize` block and `version` field |
| 166 | + |
| 167 | +### 6. LLM-as-Judge (POC) |
| 168 | + |
| 169 | +A proof-of-concept for delegating policy decisions to an LLM when deterministic CEL expressions aren't sufficient. For example, evaluating whether content is appropriate, whether a tool call is consistent with stated intent, or whether a response contains hallucinated claims. |
| 170 | + |
| 171 | +**Scope for v1.0.0:** POC only. The goal is to prove out the integration pattern and surface area, not to ship a production-grade judge. Exact design (CEL function like `judge()`, separate rule action, standalone evaluation mode) to be brainstormed during implementation. |
| 172 | + |
| 173 | +**Key questions to resolve during implementation:** |
| 174 | + |
| 175 | +- How does the judge integrate with the rule evaluation pipeline? (CEL function, post-eval hook, separate action type) |
| 176 | +- What LLM providers are supported for judging? (reuse existing codecs or separate config) |
| 177 | +- How are judge prompts specified and versioned? |
| 178 | +- Latency implications — judge calls are async/slow vs. synchronous eval |
| 179 | +- Caching and cost controls |
| 180 | +- How results feed back into the decision (hard deny, score threshold, advisory) |
| 181 | + |
| 182 | +**What ships:** A working integration that demonstrates the pattern, with at least one end-to-end test. Explicitly marked as experimental/unstable — not covered by semver guarantees until a future release. |
| 183 | + |
| 184 | +### 7. Testing & Stability |
| 185 | + |
| 186 | +**New test coverage:** |
| 187 | + |
| 188 | +- OpenAI codec: unit tests + end-to-end pipeline tests (same pattern as Anthropic) |
| 189 | +- Gemini codec: unit tests + end-to-end pipeline tests |
| 190 | +- Normalization: unit tests for mapping resolution, canonical matching, override behavior |
| 191 | +- Cross-provider: fixture-based tests showing same rules evaluated across all three codecs |
| 192 | + |
| 193 | +**Hardening:** |
| 194 | + |
| 195 | +- Fuzz testing for rule parsing and CEL compilation |
| 196 | +- Benchmark suite for engine evaluation (establish performance baseline before 1.0) |
| 197 | +- `cmd/` binaries get basic smoke tests (startup, graceful shutdown, config validation) |
| 198 | +- Audit package coverage improved from 33% to >70% |
| 199 | + |
| 200 | +## Out of Scope (1.x or Later) |
| 201 | + |
| 202 | +- MCP resources/prompts/sampling support |
| 203 | +- Plugin/extension system |
| 204 | +- Remote rule storage |
| 205 | +- Additional LLM providers beyond the big three |
| 206 | +- Web UI / dashboard |