mirror of
https://github.com/open-webui/open-terminal.git
synced 2026-11-05 01:27:28 +00:00
[PR #151] feat: insert_after/append_to_section/append + defensive replace check #141
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
open-webui/open-terminal#141
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-terminal/pull/151
Author: @dvystrcil
Created: 8/1/2026
Status: 🔄 Open
Base:
main← Head:feat/insert-append-endpoints📝 Commits (1)
e7f27befeat: insert_after/append_to_section/append + defensive replace check📊 Changes
2 files changed (+310 additions, -0 deletions)
View changed files
📝
CHANGELOG.md(+10 -0)📝
open_terminal/main.py(+300 -0)📄 Description
Motivation
I noticed a recurring failure pattern when an LLM agent wants to ADD a new section to a file: it expresses the intent as a
replace_file_contentcall with a made-uptarget(usually the heading it wants to add) and areplacementthat starts with that same text. Since the "target" never existed in the file, this just fails with a generic"Target string not found", and the model often concludes the file was truncated and goes into an unproductive re-read loop rather than realizing it needed a different operation.What this adds
Three companion operations to
replace_file_content, for ADDING rather than replacing:POST /files/insert_after-- insert content on a new line immediately after the first line matching an anchor substring.allow_multipleto insert after every match instead of erroring on ambiguity.POST /files/append_to_section-- find a markdown heading by substring, append content at the end of that section (immediately before the next heading at equal-or-shallower depth, or EOF). Correctly skips past deeper sub-headings within the section.POST /files/append-- append at end of file, handling missing trailing newlines on both sides.Also hardens
replace_file_contentitself to catch the pattern directly: whentargetis identical to the first non-empty line ofreplacement, it refuses with a specific error naming the three ops above, instead of the generic "not found" message.I know adding new endpoints is a bigger ask than a small bug fix -- happy to adjust naming/shape, split this into smaller pieces, or drop the defensive-check part if you'd rather keep
replace_file_contentuntouched. Also totally understand if this is outside what you want in scope; no worries either way.Testing
No test harness exists in this repo currently, so verified end-to-end against the real running server:
insert_afterinserts correctly after the matched anchor.append_to_sectionappends before the next heading, correctly skipping past a sub-heading's body.appendappends with correct newline handling.target != replacement's first line is unaffected by the new check.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.