graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
fix: native codedb stays callable when codedb-pro is licensed
Cursor Agent71cd9696fb9d
diff --git a/docs/adr/0040-codedb-stays-when-licensed.md b/docs/adr/0040-codedb-stays-when-licensed.mdnew file mode 100644index 00000000..2cf06fe9--- /dev/null+++ b/docs/adr/0040-codedb-stays-when-licensed.md@@ -0,0 +1,29 @@+# 0040. Native codedb stays when codedb-pro is licensed++Status: accepted 2026-08-27++## Context++v0.0.277 hid and refused native `codedb` (and `read_file`) whenever+`codedb-pro probe` succeeded, so a licensed suite was the only read/search+surface. `rlm codedb(...)` hits the same exec gate. A walk of a foreign+repo then failed with "codedb is blocked while the LICENSED+code-intelligence suite is in charge" and fell through to metered+`inspect`/`search`. Native codedb is local, indexed, and free. The+unlicensed prompt already said "always try it first."++## Decision++Native `codedb` stays in the catalog and runs, licensed or not, including+as an rlm host function. codedb-pro is an extra surface (`read`,+`faster_search`, `meta_search`, `batch`), not a replacement for codedb.+`read_file` and leading shell `cat`/`grep`/`rg` may still hide or+redirect while licensed. Companion write tools stay hidden (they bypass+`/rewind`).++## Consequences++- A licensed session can still `codedb context` / `around` / `callpath` /+ `list_dir` / `status` without loading MCP schemas first.+- `read_file` remains the paid-path default for whole-file bytes.+- Do not re-add `codedb` to `hideBuiltin` or `replacedNative`.diff --git a/docs/adr/README.md b/docs/adr/README.mdindex 656ad1dd..28e8bef7 100644--- a/docs/adr/README.md+++ b/docs/adr/README.md@@ -50,6 +50,7 @@ record only when you need the evidence or the edge cases.| [0037](0037-experiment-pool-is-opt-in.md) | `--experiment N` / `/experiment N` pre-mints a child worktree pool; the root must spawn; pool trees are listed and delivered back, never auto-deleted. || [0038](0038-in-process-acp-core.md) | Same-process embed is `libgraff` + `graff-core.wasm` + `createGraffAgent()` (ACP core, echo turn). Live coding stays `graff acp`. || [0039](0039-local-tools-are-project-scripts.md) | Agent-authored local tools are project scripts under `.graff/tools/`; skills stay instructions. Runtime catalog extras, not `schema.effectiveRootSpecs`. |+| [0040](0040-codedb-stays-when-licensed.md) | Native `codedb` stays advertised and callable when codedb-pro is licensed; pro is extra, not a replacement. |## When to write onediff --git a/src/codedbpro_report.zig b/src/codedbpro_report.zigindex c40124e3..5ae9c308 100644--- a/src/codedbpro_report.zig+++ b/src/codedbpro_report.zig@@ -142,11 +142,11 @@ pub fn fallbackOpen() bool {return g_fallback_open.load(.acquire);}-/// The native tools the licensed pro tools replace. edit_file/write_file are-/// deliberately NOT here: edits stay native regardless (they are-/// /rewind-snapshotted; codedb-pro edits bypass /rewind).+/// The native tools the licensed pro tools replace. `codedb` is never here+/// (ADR 0040 — it stays callable). edit_file/write_file stay native too+/// (/rewind-snapshotted; codedb-pro edits bypass /rewind).fn replacedNative(name: []const u8) bool {- return std.mem.eql(u8, name, "read_file") or std.mem.eql(u8, name, "codedb");+ return std.mem.eql(u8, name, "read_file");}/// A bash call is only intercepted when the search command LEADS the line —@@ -172,7 +172,7 @@ fn enforcementActive(ctx: tools.ToolCtx) bool {/// What a blocked call is pointed at. Shell searches go to zigrep — the/// suite's own CLI, run directly via bash, no MCP round trip — when the-/// binary is on PATH; reads and the codedb tool point at the pro MCP tools.+/// binary is on PATH; `read_file` points at the pro MCP read tool.fn replacementFor(call_name: []const u8, is_bash_search: bool, zigrep_installed: bool) []const u8 {if (is_bash_search) return if (zigrep_installed)"zigrep — run it directly via bash (e.g. `zigrep PATTERN src/`); it is the suite's search CLI. Caveat: zigrep always skips vendor dirs (node_modules & co) even with --no-ignore — use `rg -uu` for vendor dives"@@ -256,16 +256,6 @@ pub fn redirect(ctx: tools.ToolCtx, call: tools.ToolCall) ?Redirect {}return readRedirect(gpa, path, "full");}- if (std.mem.eql(u8, call.name, "codedb")) {- const cmd = tools.strField(call.input, "command") orelse return null;- const sub_end = std.mem.indexOfAny(u8, cmd, " \t") orelse cmd.len;- const sub = cmd[0..sub_end];- const rest = std.mem.trim(u8, cmd[sub_end..], " \t");- if (std.mem.eql(u8, sub, "outline")) return readRedirect(gpa, rest, "outline");- if (std.mem.eql(u8, sub, "read")) return readRedirect(gpa, rest, "full");- if (std.mem.eql(u8, sub, "search")) return searchRedirect(gpa, rest);- return null; // symbol/callers/deps/tree have no lossless map — refusal stays- }if (std.mem.eql(u8, call.name, "bash")) {const cmd = tools.strField(call.input, "command") orelse return null;if (!leadingSearchCommand(cmd)) return null;@@ -462,7 +452,7 @@ test "nativeRefusal: licensed pro tools block the natives they replaced" {g_fallback_open.store(false, .release);try std.testing.expect(nativeRefusal(ctx, namedCall("read_file")) != null);- try std.testing.expect(nativeRefusal(ctx, namedCall("codedb")) != null);+ try std.testing.expect(nativeRefusal(ctx, namedCall("codedb")) == null); // ADR 0040: codedb always runstry std.testing.expect(nativeRefusal(ctx, bashCall(a, "find . -name '*.zig'")) != null);try std.testing.expect(nativeRefusal(ctx, bashCall(a, "rg TODO src")) != null);try std.testing.expect(nativeRefusal(ctx, bashCall(a, "cat src/main.zig")) != null);@@ -501,12 +491,8 @@ test "redirect: blocked natives translate to their codedb-pro equivalents" {const r2 = redirect(ctx, jsonCall(a, "read_file", "{\"path\":\"a.zig\",\"start_line\":10,\"end_line\":40}")).?;try std.testing.expectEqualStrings("lines", r2.input.object.get("mode").?.string);try std.testing.expectEqualStrings("10-40", r2.input.object.get("range").?.string);- const r3 = redirect(ctx, jsonCall(a, "codedb", "{\"command\":\"outline src/main.zig\"}")).?;- try std.testing.expectEqualStrings("outline", r3.input.object.get("mode").?.string);- const r4 = redirect(ctx, jsonCall(a, "codedb", "{\"command\":\"search parseHeader\"}")).?;- try std.testing.expectEqualStrings("mcp__codedbpro__faster_search", r4.name);- try std.testing.expectEqualStrings("parseHeader", r4.input.object.get("pattern").?.string);- try std.testing.expect(redirect(ctx, jsonCall(a, "codedb", "{\"command\":\"callers foo\"}")) == null);+ try std.testing.expect(redirect(ctx, jsonCall(a, "codedb", "{\"command\":\"outline src/main.zig\"}")) == null);+ try std.testing.expect(redirect(ctx, jsonCall(a, "codedb", "{\"command\":\"search parseHeader\"}")) == null);// leading grep/rg → faster_search on the first bare token; find and piped grep stay outconst r5 = redirect(ctx, bashCall(a, "rg TODO src")).?;try std.testing.expectEqualStrings("TODO", r5.input.object.get("pattern").?.string);diff --git a/src/session_start.zig b/src/session_start.zigindex 233686a8..4a9e7dc0 100644--- a/src/session_start.zig+++ b/src/session_start.zig@@ -488,8 +488,8 @@ pub fn probeLicensed(gpa: Allocator, io: Io) bool {return skills.probeCodedbproLicensed(gpa, io);}-/// A licensed codedb-pro is IN CHARGE of reads/searches (its guard refuses-/// the native codedb/read_file and points at these tools), which inverts the+/// A licensed codedb-pro is IN CHARGE of `read_file` / leading shell searches+/// (native `codedb` stays; the guard points those at these tools), which inverts the/// #416 deferral premise: this is not a server "most sessions never call" —/// the guard makes it mandatory, and the load_tool_schemas discovery dance is/// a measured ~2 model round-trips (~8-12s) per task on K3. Pin it eager.diff --git a/src/skills.zig b/src/skills.zigindex 627027e0..2fdc911d 100644--- a/src/skills.zig+++ b/src/skills.zig@@ -63,10 +63,9 @@ pub const skills_registry = [_]SkillDef{/// Licensed-aware variant of the codedbpro note. When `codedb-pro probe`/// succeeds (paid + usable) we inject THIS instead of the conservative/// "prefer free codedb" note below — leaning into the tools the user pays for.-/// Edits inside the cwd stay native: edit_file/write_file are-/// /rewind-snapshotted and already splice via zigpatch, whereas codedb-pro-/// edit/patch/replace bypass /rewind. Explicit external targets use gated bash.-const codedbpro_note_licensed = "The codedb-pro MCP server is connected and LICENSED — its mcp__codedbpro__* tools (load once per session via load_tool_schemas, e.g. by query) REPLACE native read/search (read_file and the legacy codedb tool are hidden). Shell cat/grep/sed/head of source is redirected or refused. KEEP EDITS on native edit_file/write_file — codedb-pro write tools are hidden because they bypass /rewind. Size reads to the file: mode=full in ONE call for small files — outline/symbol/lines for files too big to read whole. Any codedb-pro failure unblocks the natives for the rest of the session.";+/// Native `codedb` is never hidden or refused (ADR 0040). Edits stay native:+/// edit_file/write_file are /rewind-snapshotted; codedb-pro writes bypass it.+const codedbpro_note_licensed = "The codedb-pro MCP server is connected and LICENSED — mcp__codedbpro__* tools (load once per session via load_tool_schemas, e.g. by query) sit alongside native codedb, which always works (context/around/callpath/list_dir/status). Prefer codedb first; reach for faster_search/meta_search when codedb cannot answer. read_file is hidden — use mcp__codedbpro__read (mode=outline first, then symbol/lines) or codedb. Shell cat/grep/sed/head of source is redirected or refused. KEEP EDITS on native edit_file/write_file — codedb-pro write tools are hidden because they bypass /rewind. Any codedb-pro failure unblocks read_file for the rest of the session.";const McpNote = struct { server: []const u8, note: []const u8 };pub const mcp_notes = [_]McpNote{@@ -393,6 +392,8 @@ test "codedbproNote: licensed flips codedbpro to the lean-in note" {try std.testing.expect(std.mem.indexOf(u8, codedbpro_note_licensed, "mcp__codedbpro__*") != null);try std.testing.expect(std.mem.indexOf(u8, codedbpro_note_licensed, "load_tool_schemas") != null);try std.testing.expect(std.mem.indexOf(u8, codedbpro_note_licensed, "/rewind") != null);+ try std.testing.expect(std.mem.indexOf(u8, codedbpro_note_licensed, "codedb, which always works") != null);+ try std.testing.expect(std.mem.indexOf(u8, codedbpro_note_licensed, "hidden") != null); // read_file / writes, never codedb}test "skillIndex: registry lookup" {diff --git a/src/tool_gates.zig b/src/tool_gates.zigindex b1700607..f348b8b9 100644--- a/src/tool_gates.zig+++ b/src/tool_gates.zig@@ -92,7 +92,7 @@ pub fn withAvailable(comptime Spec: type, arena: Allocator, base: []const Spec,}/// One catalog-assembly pass: optional tools, then #330/#lean, then the-/// licensed surface filter (hide read_file/codedb when codedb-pro is in charge).+/// licensed surface filter (hide read_file when codedb-pro is in charge; codedb stays).pub fn assembleRoot(comptime Spec: type, arena: Allocator, base: []const Spec, optional: []const Spec) ![]const Spec {const no_local_tools = @import("no_local_tools.zig");const tool_surface = @import("tool_surface.zig");diff --git a/src/tool_surface.zig b/src/tool_surface.zigindex 06096a3e..719212dc 100644--- a/src/tool_surface.zig+++ b/src/tool_surface.zig@@ -1,9 +1,10 @@-//! Licensed catalog/exec policy: one read/search surface, one edit surface.+//! Licensed catalog/exec policy: one edit surface; codedb stays native.//!-//! When codedb-pro is licensed, hide native `read_file` and legacy `codedb`.-//! Companion write tools (edit/patch/create/replace) are omitted always — they-//! bypass /rewind. Native `edit_file`/`write_file` stay. `subagent` stays.-//! webfetch is not hidden here (optional extra, not this change).+//! When codedb-pro is licensed, hide native `read_file` only. Native `codedb`+//! stays advertised and callable (ADR 0040). Companion write tools+//! (edit/patch/create/replace) are omitted always — they bypass /rewind.+//! Native `edit_file`/`write_file` stay. `subagent` stays. webfetch is not+//! hidden here (optional extra, not this change).const std = @import("std");const Allocator = std.mem.Allocator;@@ -44,7 +45,7 @@ pub fn omitMcp(qualified: []const u8) bool {/// Built-ins hidden from the advertised catalog. Never hides `subagent`.pub fn hideBuiltin(name: []const u8) bool {if (!main_mod.g_codedbpro_licensed) return false;- return std.mem.eql(u8, name, "read_file") or std.mem.eql(u8, name, "codedb");+ return std.mem.eql(u8, name, "read_file");}pub fn filterSpecs(comptime Spec: type, arena: Allocator, specs: []const Spec) ![]const Spec {@@ -126,7 +127,7 @@ test "companion writes are omitted; reads are not" {try std.testing.expect(!keepWorkerMcp("mcp__codedbpro__edit"));}-test "hideBuiltin drops read_file/codedb only when licensed; never subagent" {+test "hideBuiltin drops read_file only when licensed; codedb and subagent stay" {const saved = main_mod.g_codedbpro_licensed;defer main_mod.g_codedbpro_licensed = saved;main_mod.g_codedbpro_licensed = false;@@ -136,7 +137,7 @@ test "hideBuiltin drops read_file/codedb only when licensed; never subagent" {try std.testing.expect(!hideBuiltin("edit_file"));main_mod.g_codedbpro_licensed = true;try std.testing.expect(hideBuiltin("read_file"));- try std.testing.expect(hideBuiltin("codedb"));+ try std.testing.expect(!hideBuiltin("codedb"));try std.testing.expect(!hideBuiltin("subagent"));try std.testing.expect(!hideBuiltin("edit_file"));try std.testing.expect(!hideBuiltin("write_file"));@@ -176,13 +177,14 @@ test "filterSpecs drops hidden builtins and leaves the rest" {try std.testing.expectEqual(@as(usize, 5), all.len);main_mod.g_codedbpro_licensed = true;const filtered = try filterSpecs(FakeSpec, arena_state.allocator(), &specs);- try std.testing.expectEqual(@as(usize, 3), filtered.len);+ try std.testing.expectEqual(@as(usize, 4), filtered.len);try std.testing.expectEqualStrings("bash", filtered[0].name);try std.testing.expectEqualStrings("edit_file", filtered[1].name);- try std.testing.expectEqualStrings("subagent", filtered[2].name);+ try std.testing.expectEqualStrings("codedb", filtered[2].name);+ try std.testing.expectEqualStrings("subagent", filtered[3].name);}-test "licensed root catalog drops read_file and codedb, keeps subagent and edit_file" {+test "licensed root catalog drops read_file, keeps codedb and subagent and edit_file" {const schema = @import("schema.zig");const saved = main_mod.g_codedbpro_licensed;defer main_mod.g_codedbpro_licensed = saved;@@ -205,15 +207,17 @@ test "licensed root catalog drops read_file and codedb, keeps subagent and edit_const on = try schema.effectiveRootSpecs(a);var saw_edit = false;var saw_sub2 = false;+ var saw_codedb = false;for (on) |t| {try std.testing.expect(!std.mem.eql(u8, t.name, "read_file"));- try std.testing.expect(!std.mem.eql(u8, t.name, "codedb"));+ if (std.mem.eql(u8, t.name, "codedb")) saw_codedb = true;if (std.mem.eql(u8, t.name, "edit_file")) saw_edit = true;if (std.mem.eql(u8, t.name, "subagent")) saw_sub2 = true;if (std.mem.eql(u8, t.name, "write_file")) {}}try std.testing.expect(saw_edit);try std.testing.expect(saw_sub2);+ try std.testing.expect(saw_codedb);}test "skipOptionalServer keeps deepwiki/mobbin opt-in" {@@ -227,7 +231,7 @@ test "skipOptionalServer keeps deepwiki/mobbin opt-in" {try std.testing.expect(!skipOptionalServer("mobbin", env));}-test "worker specs drop read_file/codedb; worker MCP keeps reads not writes" {+test "worker specs drop read_file, keep codedb; worker MCP keeps reads not writes" {const schema = @import("schema.zig");const saved = main_mod.g_codedbpro_licensed;defer main_mod.g_codedbpro_licensed = saved;@@ -237,13 +241,15 @@ test "worker specs drop read_file/codedb; worker MCP keeps reads not writes" {const a = arena_state.allocator();const specs = try filterSpecs(@TypeOf(schema.base_specs[0]), a, schema.base_specs[0..]);var saw_edit = false;+ var saw_codedb = false;for (specs) |t| {try std.testing.expect(!std.mem.eql(u8, t.name, "read_file"));- try std.testing.expect(!std.mem.eql(u8, t.name, "codedb"));try std.testing.expect(!std.mem.eql(u8, t.name, "subagent"));+ if (std.mem.eql(u8, t.name, "codedb")) saw_codedb = true;if (std.mem.eql(u8, t.name, "edit_file")) saw_edit = true;}try std.testing.expect(saw_edit);+ try std.testing.expect(saw_codedb);const fake = [_]mcp.Tool{.{ .server_index = 0, .original_name = "read", .qualified_name = "mcp__codedbpro__read", .description = "d", .input_schema = .null },.{ .server_index = 0, .original_name = "edit", .qualified_name = "mcp__codedbpro__edit", .description = "d", .input_schema = .null },