[PR #439] fix(deepagents): stop double line numbers in read_file for sandbox backends #463

Open
opened 2026-06-05 17:23:16 -04:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/deepagentsjs/pull/439
Author: @alvedder
Created: 4/8/2026
Status: 🔄 Open

Base: mainHead: alvedder/fix-double-numbers


📝 Commits (1)

  • a72815c fix(deepagents): stop double line numbers in read_file for sandbox backends

📊 Changes

5 files changed (+547 additions, -681 deletions)

View changed files

📝 libs/deepagents/src/backends/composite.ts (+32 -68)
📝 libs/deepagents/src/backends/filesystem.ts (+88 -140)
📝 libs/deepagents/src/backends/sandbox.test.ts (+298 -296)
📝 libs/deepagents/src/backends/sandbox.ts (+60 -91)
📝 libs/standard-tests/src/tests/read.ts (+69 -86)

📄 Description

Sandbox read() used awk to emit cat-n–style NR + tab + line, and the read_file tool then ran formatContentWithLineNumbers again. Text reads showed two numeric columns e.g.

     1	     1	{
     2	     2		"name": "monorepo",
     3	     3		"version": "1.0.0",
...

This aligns sandbox text read() with FilesystemBackend: raw sliced lines from the backend; one numbering pass in the tool.

Changes

  • buildReadCommand (libs/deepagents/src/backends/sandbox.ts): keep the same existence / empty-file checks and NR range (1-based inclusive slice from 0-based offset/limit); replace numbered printf with { print } so stdout is unnumbered lines only.
  • Docs: Clarify on BaseSandbox.read, FilesystemBackend.read, CompositeBackend.read, and buildReadCommand that text read() returns a raw line slice; cat-n formatting is applied in read_file.
  • Tests (libs/deepagents/src/backends/sandbox.test.ts):
    • Helper + test that read_file output has exactly one tab-separated “line number + body” segment per line (no extra leading number column) when using MockSandbox + createFilesystemMiddleware.
    • MockSandbox: simulate the real awk slice (NR >= start && NR <= end) and return raw joined lines (no prefixes).
    • Assert text reads use awk with { print }.
  • @langchain/sandbox-standard-tests: rename the misleading read() case from “with line numbers” to reflect raw backend output.

Testing

  • pnpm exec vitest run src/backends/sandbox.test.ts --typecheck (and related fs unit tests as appropriate).

Notes

  • Binary reads are unchanged (still via downloadFiles).
  • Callers that depended on numbered strings from backend.read() on sandboxes should switch expectations to raw lines (same as filesystem/state backends); numbering belongs to tool/UI layers that call formatContentWithLineNumbers.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langchain-ai/deepagentsjs/pull/439 **Author:** [@alvedder](https://github.com/alvedder) **Created:** 4/8/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `alvedder/fix-double-numbers` --- ### 📝 Commits (1) - [`a72815c`](https://github.com/langchain-ai/deepagentsjs/commit/a72815c09a1e96567d979c7f683323027e8fe8e9) fix(deepagents): stop double line numbers in read_file for sandbox backends ### 📊 Changes **5 files changed** (+547 additions, -681 deletions) <details> <summary>View changed files</summary> 📝 `libs/deepagents/src/backends/composite.ts` (+32 -68) 📝 `libs/deepagents/src/backends/filesystem.ts` (+88 -140) 📝 `libs/deepagents/src/backends/sandbox.test.ts` (+298 -296) 📝 `libs/deepagents/src/backends/sandbox.ts` (+60 -91) 📝 `libs/standard-tests/src/tests/read.ts` (+69 -86) </details> ### 📄 Description Sandbox `read()` used `awk` to emit cat-n–style `NR` + tab + line, and the `read_file` tool then ran `formatContentWithLineNumbers` again. Text reads showed **two** numeric columns e.g. ``` 1 1 { 2 2 "name": "monorepo", 3 3 "version": "1.0.0", ... ``` This aligns sandbox text `read()` with `FilesystemBackend`: **raw sliced lines** from the backend; **one** numbering pass in the tool. ## Changes - **`buildReadCommand`** (`libs/deepagents/src/backends/sandbox.ts`): keep the same existence / empty-file checks and `NR` range (1-based inclusive slice from 0-based `offset`/`limit`); replace numbered `printf` with **`{ print }`** so stdout is unnumbered lines only. - **Docs**: Clarify on `BaseSandbox.read`, `FilesystemBackend.read`, `CompositeBackend.read`, and `buildReadCommand` that text `read()` returns a **raw** line slice; cat-n formatting is applied in **`read_file`**. - **Tests** (`libs/deepagents/src/backends/sandbox.test.ts`): - Helper + test that `read_file` output has **exactly one** tab-separated “line number + body” segment per line (no extra leading number column) when using `MockSandbox` + `createFilesystemMiddleware`. - **`MockSandbox`**: simulate the real `awk` slice (`NR >= start && NR <= end`) and return **raw** joined lines (no prefixes). - Assert text reads use `awk` with `{ print }`. - **`@langchain/sandbox-standard-tests`**: rename the misleading `read()` case from “with line numbers” to reflect **raw** backend output. ## Testing - `pnpm exec vitest run src/backends/sandbox.test.ts --typecheck` (and related `fs` unit tests as appropriate). ## Notes - **Binary** reads are unchanged (still via `downloadFiles`). - Callers that depended on **numbered** strings from `backend.read()` on sandboxes should switch expectations to raw lines (same as filesystem/state backends); numbering belongs to tool/UI layers that call `formatContentWithLineNumbers`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-06-05 17:23:16 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/deepagentsjs#463