Repository navigation
tools: verb_noun file-tool names + append_file + edit_file str-replace + apply_patch - #407
Conversation
Renames the core file tools to the verb_noun convention models are
trained on (openclaw / picoclaw / Claude Code): fs_read->read_file,
fs_write->write_file, fs_list->list_dir, fs_grep->grep_files,
fs_edit_hashline->edit_file. The old names stay registered as HIDDEN
back-compat aliases (new TTool.Hidden flag + TToolRegistry.RegisterHidden):
they dispatch normally via Find/RunTool so existing configs, saved
sessions, and mid-session calls keep working, but ToProviderDefs skips
them so the model only ever sees the new canonical names.
New capabilities:
* append_file -- append to a file (create + parent dirs when missing).
The incremental-write escape hatch: build a large file across turns
instead of one oversized write_file arg a provider may fail to
serialise (Gemini MALFORMED_FUNCTION_CALL).
* edit_file gains a default old_text/new_text string-replacement mode
(unique match unless replace_all; omit new_text to delete) -- the
form every model authors natively. The hashline `patch` mode stays as
an advanced option, still gated to UseHashline in the advertised
schema. edit_file now registers UNCONDITIONALLY, so --no-hashline
deployments finally get a real edit tool instead of none.
Wiring updated to recognise the new names where a tool name drives
behaviour: the tool-loop patch preflight/format-retry, the auto-router
write/run heuristic, the checkpoint mutation detector, and the gateway
tool-view summariser all match the new names (and keep the old ones for
replayed history). System prompt, plan-mode text, tool descriptions,
onboarding, and README updated to the new names; the old names are noted
as hidden aliases.
Test: fs_tool_naming_tests -- provider defs advertise new names + hide
aliases, old names still dispatch, append_file concatenates/creates,
edit_file str-replace (unique / not-found / ambiguous / replace_all /
delete). Full build + touched-subsystem suites green.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6
…h edit_file) read_file emitted the hashline #hash+LINENO format by default (when enabled) with plain:true as the opt-out -- the inverse of edit_file, whose default is now plain old_text/new_text string edits with the hashline patch as an advanced opt-in. Flip read_file to match: plain text is the default (clean content is what edit_file matches against and what smaller models handle best), and the hashline format is opt-in via a hashline:true arg, still gated to UseHashline. The legacy plain:true arg stays accepted as a harmless no-op. edit_file's patch-mode help now tells the model to read with hashline:true first to get the #hash header. Test extended: read_file defaults to plain, hashline:true emits the header + LINENO lines. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6
New apply_patch tool in the Codex / OpenClaw apply_patch format: one call carrying a "*** Begin Patch" ... "*** End Patch" envelope with any mix of "*** Add File" / "*** Update File" (+ optional "*** Move to") / "*** Delete File" sections. Update hunks use " " context / "-" remove / "+" add lines and optional "@@ context" anchors; edits are located by their context and removed lines, not by line number. It fills the niche openclaw's apply_patch does and edit_file's single old_text/new_text swap can't: a change that spans multiple files or many hunks. All-or-nothing -- the whole patch is parsed and every hunk located (against the on-disk files) BEFORE anything is written, and every target is sandbox-checked up front, so a mislocated hunk writes nothing. Each written/deleted file is snapshotted for /undo. Wired into the auto-router write/run heuristic and the gateway tool-view summary; refused under Plan mode via its tcMutating category. Registered unconditionally (no hashline dependency). README + plan-mode tool lists updated. Test: fs_tool_naming_tests gains an update+add+delete patch and an atomic-failure case (a mislocated hunk leaves the file untouched). Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e987a50616
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| pokAdd: | ||
| begin | ||
| SnapshotBeforeWrite(Actions[i].Path); | ||
| WriteFileText(Actions[i].Path, Actions[i].Content); |
There was a problem hiding this comment.
Refuse add/move targets that already exist
When an apply_patch contains *** Add File: <path> for a path that already exists, this branch calls WriteFileText, whose implementation opens with fmCreate, so it silently truncates/replaces the existing file and reports it as added. The same create-target issue applies to *** Move to:. In a model-authored patch, using Add File instead of Update File would clobber user content rather than failing; please preflight existing targets and abort before writing.
Useful? React with 👍 / 👎.
| if FTools[i].Hidden then | ||
| Continue; |
There was a problem hiding this comment.
Keep hidden aliases out of every tool listing
Filtering Hidden only in ToProviderDefs leaves the old fs_* aliases visible in other model-facing paths: default subagents expand Source.Names in BuildFilteredRegistry and re-register each hidden alias with Register, which clears Hidden, and the MCP server's tools/list also iterates FRegistry.Names. In those contexts the model still sees both the renamed tools and the back-compat aliases despite this “only the new canonical name is advertised” contract; skip hidden entries in Names consumers or preserve/filter the flag there too.
Useful? React with 👍 / 👎.
…review fixes) Two #407 review findings. 1. apply_patch clobbered existing files. "*** Add File: <path>" (and a "*** Move to:" destination) went straight to WriteFileText, which opens fmCreate and truncates -- so a model that used Add File instead of Update File silently overwrote user content and reported it as "added". Preflight now refuses an Add/Move-to target that already exists, before any write (the patch stays all-or-nothing). 2. Hidden aliases leaked into non-provider listings. ToProviderDefs skipped Hidden, but Names did not -- and Names feeds the subagent '*' expansion (BuildFilteredRegistry re-registers each name via Register, which clears Hidden) and the MCP server's tools/list, so subagents and MCP clients saw both the new tool and the old fs_* alias. Names now skips Hidden entries; dispatch still goes through Find, which resolves hidden names, so back-compat is unaffected. Tests: apply_patch refuses Add onto an existing path and leaves it intact; Registry.Names excludes fs_write / fs_edit_hashline while keeping the canonical names. subagent-default / subagent-bg / mcp-server / autoroute suites still green. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6
Brings the file toolset in line with the conventions models are trained on (openclaw / picoclaw / Claude Code), so a mid-tier model spends its budget on the task instead of on PasClaw's bespoke tool names/formats. Three commits.
1. Rename to verb_noun, with hidden back-compat aliases
fs_read→read_file,fs_write→write_file,fs_list→list_dir,fs_grep→grep_files,fs_edit_hashline→edit_file.A new
TTool.Hiddenflag +TToolRegistry.RegisterHiddenregister the old names as hidden aliases: they still dispatch viaFind/RunTool(existing configs, saved sessions, and mid-session calls keep working), butToProviderDefsskips them so the model only ever sees the new names.2. New capabilities
append_file— append to a file (create + parent dirs when missing). The incremental-write escape hatch: build a large file across turns instead of one oversizedwrite_filearg a provider may fail to serialise.edit_filestring-replacement mode — defaultold_text→new_text(unique match unlessreplace_all; omitnew_textto delete), the form every model authors natively. The hashlinepatchmode stays as an advanced opt-in, still gated toUseHashlinein the advertised schema.edit_filenow registers unconditionally, so--no-hashlinedeployments finally get a real edit tool.read_filesymmetry — plain text is now the default; the hashline#hash+LINENOformat is opt-in viahashline:true(mirrorsedit_file's advancedpatch; the patch workflow reads withhashline:truefirst). Legacyplain:truestill accepted as a no-op.3.
apply_patch— multi-file, context-anchored patchesNew tool in the Codex/OpenClaw
apply_patchformat: one call with a*** Begin Patch…*** End Patchenvelope mixing*** Add File/*** Update File(+ optional*** Move to) /*** Delete File. Update hunks use/-/+lines and optional@@anchors; edits are located by context, not line numbers. All-or-nothing — the whole patch is parsed and every hunk located against the on-disk files, and every target sandbox-checked, before anything is written. Each write/delete is snapshotted for/undo. Fills the niche a singleedit_fileswap can't: a change spanning multiple files or many hunks.Wiring
Name-driven behaviour updated to the new names (keeping old ones for replayed history): the tool-loop patch preflight/format-retry, the auto-router write/run heuristic, the checkpoint mutation detector, and the gateway tool-view summary. System prompt, plan-mode text, tool descriptions, onboarding, and README updated; old names noted as hidden aliases.
Tests
New
fs_tool_naming_tests: provider defs advertise new names + hide aliases, old names still dispatch,read_fileplain-by-default/hashline:trueopt-in,append_fileconcatenate/create,edit_filestr-replace (unique / not-found / ambiguous / replace_all / delete), andapply_patch(update+add+delete + atomic-on-failure). Full build + touched-subsystem suites (toolview, autoroute, hashline, subagent-default, plan-build-mode) green.🤖 Generated with Claude Code
https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6
Generated by Claude Code