Skip to content

Bug: read_file line numbers are duplicated when using a sandbox backend #679

Description

Summary

When a file is read through any sandbox backend (BaseSandbox / its subclasses in libs/deepagents/src/backends/sandbox.ts), the output shows line numbers twice on every line, e.g.:

     1	     1	import { foo } from "bar";
     2	     2	const x = 1;

instead of the expected single column:

     1	import { foo } from "bar";
     2	const x = 1;

Root cause

Line numbering is applied in two places for sandbox reads:

  1. The backend. buildReadCommand() in libs/deepagents/src/backends/sandbox.ts builds an awk command that prepends line numbers itself:

    awk 'NR >= ${start} && NR <= ${end} { printf "%6d\t%s\n", NR, $0 }' ${quotedPath}
  2. The middleware. The shared read_file tool in libs/deepagents/src/middleware/fs.ts (line ~773) unconditionally re-numbers whatever content the backend returns:

    let formatted = formatContentWithLineNumbers(content, offset + 1);

Proposed fix

Change the awk command in buildReadCommand() to emit only the line content:

awk 'NR >= ${start} && NR <= ${end} { printf "%s\n", $0 }' ${quotedPath}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions