feat(chat-workflow): port 7 leaf sandbox tools — read/write/edit/grep…

Merged
SW
5mo ago
+1491-75

…/glob/todo/web_fetch (PR 5)

Builds on PR 4 (bash + wire-up) by porting the remaining leaf tools from open-agents/packages/agent/tools/. Each is a direct port adapted to api's Sandbox interface, registered in buildAgentTools, and ready for the agent to invoke through the existing experimental_context plumbing.

New tool files (one tool per file, per sweetman SRP):

  • readFileTool.ts — read with 1-indexed offset/limit, numbered output
  • writeFileTool.ts — create / overwrite (with mkdir -p) on sandbox.writeFile
  • editFileTool.ts — exact-string replace, ambiguous-match rejection
  • grepTool.ts — POSIX ERE search via grep -rn, capped at 100/10/200
  • globTool.ts — find -printf with mtime sort, GNU/BSD-compatible
  • todoWriteTool.ts — stateless planning surface; echoes the list back
  • webFetchTool.ts — curl from inside the sandbox, body truncated at 10KB

New helpers (utilities used by multiple tools):

  • shellEscape.ts — ' → '\'' dance
  • toDisplayPath.ts — absolute → relative-when-inside-workdir display path

buildAgentTools registers all 8 leaf tools (bash + 7 new). The composite tools (task, ask_user_question, skill) need subagent context / UI rendering / skill discovery infrastructure not in api today and land in a follow-up PR.

Tests: 50 new across the 7 tools + 2 helpers + factory. Full suite 3014/3014; lint clean; production build succeeds.


Summary by cubic

Add seven sandbox leaf tools (read, write, edit, grep, glob, todo_write, web_fetch) and register them in buildAgentTools to enable file ops, search, planning, and HTTP fetch from inside the sandbox. Includes helpers and tests; composite tools will follow later.

  • New Features

    • read: Numbered output with 1-indexed offset/limit; rejects directories.
    • write: Creates parent dirs and overwrites file content.
    • edit: Exact-string replace; rejects ambiguous matches unless replaceAll; returns startLine and count.
    • grep: POSIX ERE via grep -rn; caps to 100 total/10 per file/200 chars per line; exit 1 = no matches.
    • glob: GNU/BSD-compatible find; mtime-sorted; skips dotfiles and node_modules; default limit 100.
    • todo_write: Stateless planning surface that echoes the full todo list.
    • web_fetch: curl inside the sandbox with method/headers/body; body truncated at 10KB; returns status.
    • Helpers: shellEscape for safe shell args; toDisplayPath for workspace-relative display paths.
    • buildAgentTools: Registers bash + the 7 new tools as direct exports; adds tests for tools, helpers, and factory.
  • Refactors

    • Harmonized tool exports to direct values (no factory wrappers); updated buildAgentTools and tests accordingly.