sdk-python icon indicating copy to clipboard operation
sdk-python copied to clipboard

[BUG] TS harness: edit expands $$ and $& replacement patterns in new_str instead of inserting it literally

Open arronbailiss opened this issue 1 week ago • 0 comments

Human Overview

To be filled in by a human (AI-drafted issue, see team/AI_USAGE_POLICY.md).

Checks

  • [x] I have updated to the lastest minor and patch version of Strands
  • [x] I have checked the documentation and this is not expected behavior
  • [x] I have searched ./issues and there are no duplicates of my issue

SDK Language

TypeScript

Strands Version

main @ 794d37c6e (@strands-agents/harness 0.0.1-development); also present at 7296caba7

Language Runtime Version

Node.js 24.15.0

Operating System

macOS 26.7.3

Installation Method

git clone

Steps to Reproduce

The harness edit tool replaces with String.prototype.replace and a string pattern, which still expands $$, $&, $` and $' in the replacement. An edit whose new_str contains them (a shell $$, a regex replacement string, template code) writes something else.

import { mkdtempSync, readFileSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { Agent } from '@strands-agents/sdk'
import { edit } from '@strands-agents/harness'

const file = join(mkdtempSync(join(tmpdir(), 'edit-')), 'script.sh')
writeFileSync(file, 'echo PID\n')
const agent = new Agent({ tools: [edit], printer: false })
await agent.tool.edit!.invoke({ path: file, old_str: 'PID', new_str: "$$ $& $'" }, { recordDirectToolCall: false })
console.log(JSON.stringify(readFileSync(file, 'utf8')))

Expected Behavior

new_str is inserted literally: "echo $$ $& $'\n".

Actual Behavior

"echo $ PID \n\n": $$ collapsed to $, $& inserted the matched text and $' inserted the text after the match. The tool still reports Edited <path>., so the model does not notice.

Additional Context

The SDK's own edit and notebook tools insert new_str literally (strands-ts/src/vended-tools/edit/edit.ts:77, strands-ts/src/vended-tools/notebook/notebook.ts:303), as do the Python harness and SDK edit tools (harness-py/src/strands_harness/tools/file_tools.py:187, strands-py/src/strands/vended_tools/edit/edit.py:78). Only the TypeScript harness tool (harness-ts/src/tools/file-tools.ts:221 on main 794d37c6e) expands the patterns.

arronbailiss avatar Nov 20 '26 18:11 arronbailiss