Skip to content

tools: verb_noun file-tool names + append_file + edit_file str-replace + apply_patch - #407

Merged
FMXExpress merged 4 commits into
mainfrom
claude/fs-tool-naming
Jul 1, 2026
Merged

FMXExpress merged 4 commits into
mainfrom
claude/fs-tool-naming

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

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.Hidden flag + TToolRegistry.RegisterHidden register the old names as hidden aliases: they still dispatch via Find/RunTool (existing configs, saved sessions, and mid-session calls keep working), but ToProviderDefs skips 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 oversized write_file arg a provider may fail to serialise.
  • edit_file string-replacement mode — default old_text→new_text (unique match unless replace_all; omit new_text to delete), the form every model authors natively. The hashline patch mode stays as an advanced opt-in, still gated to UseHashline in the advertised schema. edit_file now registers unconditionally, so --no-hashline deployments finally get a real edit tool.
  • read_file symmetry — plain text is now the default; the hashline #hash+LINENO format is opt-in via hashline:true (mirrors edit_file's advanced patch; the patch workflow reads with hashline:true first). Legacy plain:true still accepted as a no-op.

3. apply_patch — multi-file, context-anchored patches

New tool in the Codex/OpenClaw apply_patch format: one call with a *** Begin Patch … *** End Patch envelope 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 single edit_file swap 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_file plain-by-default/hashline:true opt-in, append_file concatenate/create, edit_file str-replace (unique / not-found / ambiguous / replace_all / delete), and apply_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

claude added 3 commits July 1, 2026 13:59
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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +266 to +267
if FTools[i].Hidden then
Continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants