Skip to content

codedb_read: ranged output is line-number-prefixed (not byte-exact) — add a raw read mode #632

Closed

Description

@justrach

Problem

codedb_read with a line range returns line-number-prefixed output — handleRead calls extractLines(content, start, end, /*line_numbers=*/true, …) (hardcoded) and also always prepends hash:<x>\n. So a ranged read is not a byte-exact copy of the source.

Consequence on the agent read path: an agent that located code via codedb_symbol/codedb_search cannot use codedb_read's ranged output as the old_string for an exact-match editor — the 234 | prefixes won't match. So it falls back to a native file read for the pre-edit span, and codedb only ever serves locate, never read+edit. This is the codedb half of justrach/codegraff#66 (graff routes raw reads to its native tool for exactly this reason).

Failing test (src/test_mcp.zig, fails on main)

test "issue-632: codedb_read raw mode returns byte-exact range without line-number prefixes" {
    // ... tmpdir with "alpha\nbeta\ngamma\n", BenchContext, Explorer ...
    // args: {"path":"small.txt","line_start":1,"line_end":2,"raw":true}
    bench_ctx.runDispatch(io, alloc, .codedb_read, &args, &out, &store, &explorer, &agents);
    try testing.expect(std.mem.indexOf(u8, out.items, "alpha\nbeta") != null); // exact bytes
    try testing.expect(std.mem.indexOf(u8, out.items, " | ") == null);        // no line-num prefix
}

Current behavior: ranged output is 1 | alpha\n 2 | beta, so " | " is present and the second assertion fails (error.TestUnexpectedResult). raw:true is silently ignored.

Expected

A raw/byte-exact mode (e.g. raw: true) returns the exact source lines for the range with no line-number prefix (and the hash line suppressed or kept clearly separable), so codedb_read can feed an exact-string edit and serve the full read→edit loop, not just locate.

Fix (sketch)

  • Read a raw (or number) bool arg in handleRead; pass !raw as extractLines's line_numbers.
  • In raw mode, omit the hash: header (or move it out-of-band) so the body is verbatim.
  • Keep the default (prefixed) unchanged for human/inspection use.

Activity

  1. justrach commented on Jun 22, 2026

    @justrach
    OwnerAuthor

    Fixed on release/0.2.5826: codedb_read raw mode returns byte-exact ranged output (e8df164, test 375989e + broadened coverage c72a129). Ships in 0.2.5826.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions