Skip to content

Replace File API: Add replacement result feedback #982

@Pangjiping

Description

@Pangjiping

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:

  1. No replacement result feedback — Returns HTTP 200 + empty body on success, without indicating how many replacements were made
  2. Replaces all matches — Uses strings.ReplaceAll under the hood, replacing every occurrence of oldContent with no option to limit to first match
  3. 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.goReplaceContent()

Proposed Changes

  1. Add a replacedCount field per file in the response, returning the actual number of replacements made
  2. When oldContent doesn't match (replacedCount=0), callers can detect that the replacement had no effect
  3. (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

Metadata

Metadata

Assignees

No one assigned
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions