Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

sealosdevbox 沙盒编辑文件时按正则替换,含特殊字符或多行的内容会改错或不修改

Closed
#8,119 1 comment 1 reaction 1 assignee View on GitHub

Maintainers usually reply within 1 day

@DigHuang is already working on this.

Since Oct 26, 2026.

  • #8120 by @RaphaelFakhri — open

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
typescript
Domain
backend

Research direction

Start with sdk/sandbox-adapter/src/polyfills/command-filesystem.ts and trace CommandFilesystemPolyfill.replaceContent and readFile. Reproduce the literal, backslash, multiline, and missing-file cases described in the issue; check the linked pull request #8120 for work already underway. Done means replacements preserve the requested text, multiline matches work, and missing files return an error.

Written by the indexing model from the issue text.

Description

使用 sealosdevbox 沙盒时,Agent 的编辑文件工具调用 CommandFilesystemPolyfill.replaceContent,内部执行 sed -i 's/<old>/<new>/g'。oldContent 被当作 sed 正则并按行匹配:

  1. .、*、[、^、$ 按正则解释,可能匹配不到,或改到其他位置。
  2. 反斜杠被转义为 4 个,sed 查找的是两个反斜杠;newContent 中的单个 \ 写入后变成两个。
  3. 跨行的 oldContent 报错 sed: -e expression #1, char 3: unterminated 's' command。
  4. 未匹配时 sed 返回 0,工具回复编辑成功,文件实际未变。

另外,readFile 在 stat 失败时执行 cat file | base64 -w 0,文件不存在时退出码为 0,读取结果为空内容,而不是 FILE_NOT_FOUND。

复现步骤

  1. 在 sealosdevbox 沙盒中创建文件,内容为 const re = /a.b*/;。
  2. 调用编辑文件工具:oldContent: "/a.b*/",newContent: "/a\\.b+/"。
  3. 工具返回 Files edited successfully,文件内容未变。

预期行为

oldContent 按字面量匹配,支持多行;替换结果与输入一致;文件不存在时返回错误。

环境

  • FastGPT main(749809070b)
  • 沙盒提供方:sealosdevbox(sdk/sandbox-adapter/src/polyfills/command-filesystem.ts)
Dominant language
TypeScript
Stars
29.9k
Forks
7.3k
Avg merge
1d 6h
Merged PRs (30d)
226

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from labring/FastGPT

All issues in labring/FastGPT

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.