Background
Users report that the Replace File Content API (POST /files/replace) does not return whether the replacement succeeded. When oldContent doesn't match or matches multiple locations, callers have no way to know.
Current Behavior
The current implementation (execd ReplaceContent handler) has these issues:
- No replacement result feedback — Returns HTTP 200 + empty body on success, without indicating how many replacements were made
- Replaces all matches — Uses
strings.ReplaceAll under the hood, replacing every occurrence of oldContent with no option to limit to first match
- Silent success on no match — When
oldContent doesn't match at all, the file is rewritten as-is and still returns 200. Callers cannot distinguish "replaced successfully" from "nothing matched"
Related code: OpenSandbox/components/execd/pkg/web/controller/filesystem.go → ReplaceContent()
Proposed Changes
- Add a
replacedCount field per file in the response, returning the actual number of replacements made
- When
oldContent doesn't match (replacedCount=0), callers can detect that the replacement had no effect
- (Optional) Support
replaceFirst / replaceAll mode control, allowing callers to replace only the first match
Scope of Impact
execd handler response format change
- OpenAPI spec update
- Language SDK adaptation (Python/Go/Java/Node) for new response format
- Documentation update
Background
Users report that the Replace File Content API (
POST /files/replace) does not return whether the replacement succeeded. WhenoldContentdoesn't match or matches multiple locations, callers have no way to know.Current Behavior
The current implementation (
execdReplaceContent handler) has these issues:strings.ReplaceAllunder the hood, replacing every occurrence ofoldContentwith no option to limit to first matcholdContentdoesn't match at all, the file is rewritten as-is and still returns 200. Callers cannot distinguish "replaced successfully" from "nothing matched"Related code:
OpenSandbox/components/execd/pkg/web/controller/filesystem.go→ReplaceContent()Proposed Changes
replacedCountfield per file in the response, returning the actual number of replacements madeoldContentdoesn't match (replacedCount=0), callers can detect that the replacement had no effectreplaceFirst/replaceAllmode control, allowing callers to replace only the first matchScope of Impact
execdhandler response format change