Skip to content

feat(tools): indentation-tolerant matching and stale-read detection for Edit/MultiEdit - #608

Merged
edenreich merged 8 commits into
mainfrom
feat/indentation-tolerant-matching
Jun 6, 2026
Merged

edenreich merged 8 commits into
mainfrom
feat/indentation-tolerant-matching

Conversation

@edenreich

@edenreich edenreich commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Makes the Edit and MultiEdit tools more robust for agent-driven editing. Two related changes:

1. Indentation-tolerant matching

When an exact old_string match fails, the tools fall back to a whitespace-tolerant match instead of erroring. The fallback:

  • locates the block by comparing lines after trimming surrounding whitespace,
  • applies only when exactly one block matches (ambiguous matches still error),
  • re-indents new_string to the file's actual indentation via a per-indent-level map.

This fixes the common cases that made weaker models thrash on tab-indented Go: off-by-N tabs, tabs↔spaces, and column-0 header blocks (type X struct {, func, import () with an indented body. The exact-match path, uniqueness guard, and MultiEdit atomicity are unchanged. A new tools.edit.strict_whitespace option (default false) disables the fallback for byte-exact-only matching. Normalized edits are surfaced in result metadata.

2. Stale-read detection

The Read tool snapshots a file's modtime/size when it reads it. Before an Edit/MultiEdit, the tool compares the file against that snapshot; if it changed since the last read (external modification), the edit is rejected with an explicit error telling the model to re-read first. The agent's own writes refresh the snapshot, so consecutive edits are not falsely rejected. Prevents the agent silently clobbering changes made under it.

Key files

  • internal/agent/tools/flexmatch.go (new) — whitespace-tolerant matcher + per-indent re-indentation.
  • internal/agent/tools/edit.go, multiedit.go — flexible fallback wiring + stale-read check.
  • internal/agent/tools/registry.go, internal/services/tools.go — per-file read snapshots (record on Read, refresh on Edit/MultiEdit/Write).
  • config/config.go — tools.edit.strict_whitespace.
  • internal/domain/interfaces.go — additive result fields (WhitespaceNormalized, NormalizedEdits).
  • Docs (docs/configuration-reference.md, docs/tools-reference.md) + tests updated.

Config

tools:
  edit:
    strict_whitespace: false # true => byte-exact matching only (disables the fallback)

Testing

  • task test — new flexible-match cases (off-by-one tab, tabs↔spaces, column-0 struct/import, ambiguous/inconsistent → still error) + stale-read reject/allow + atomic-abort.
  • task lint, task build

Notes

No cross-repo impact; tool behavior + config are CLI-internal and documented in-repo, so no separate inference-gateway/docs ticket is needed.

@edenreich
edenreich requested a review from a team as a code owner June 5, 2026 23:47
edenreich added 6 commits June 6, 2026 01:48
… finish (#609)

## Summary

This PR fixes the overlap between tool approval and execution -
previously, tools only started executing *after* all approvals were
collected, wasting time. Now each approved tool runs immediately as the
user approves it, and tools run concurrently.

### Changes

1. **fix(agent): execute approved tools concurrently while approving the
rest** (d5598e2)
- Approval prompts stay sequential, but each approved tool"'s execution
is spawned immediately
   - Tools run in parallel (bounded by `agent.max_concurrent_tools`)
- Results are recorded in index-keyed slots and flushed to the
conversation in tool-call order

2. **fix(agent): freeze per-tool ticker when an approved tool finishes**
(5caa035)
- `executeToolInternal` publishes its own terminal completed/failed
status via a `defer`
- The per-tool elapsed-time ticker freezes the moment the tool finishes
- Removes redundant external publishes from `executeToolCallsParallel`
to avoid double-publish flickering

3. **fix(tui): refresh conversation history when a tool finishes
executing** (0906249)
- Tool coordinator now emits an `UpdateHistoryEvent` on completed/failed
tool execution
- Freshly flushed tool results replace their "Approved" placeholder
immediately

4. **refactor: inject agent config directly into EventDrivenAgent**
(44986f0)
   - Clean up how config is passed to the agent
@edenreich edenreich changed the title Add indentation-tolerant matching for Edit and MultiEdit tools feat(tools): indentation-tolerant matching and stale-read detection for Edit/MultiEdit Jun 6, 2026
@edenreich
edenreich merged commit 14d7e98 into main Jun 6, 2026
@edenreich
edenreich deleted the feat/indentation-tolerant-matching branch June 6, 2026 10:28
inference-gateway-releaser Bot pushed a commit that referenced this pull request Jun 6, 2026
## [0.119.0](v0.118.0...v0.119.0) (2026-06-06)

### 🚀 Features

* add npm wrapper to install and run the CLI via npx ([#610](#610)) ([8f24fd5](8f24fd5)), closes [inference-gateway/docs#182](inference-gateway/docs#182)
* **tools:** indentation-tolerant matching and stale-read detection for Edit/MultiEdit ([#608](#608)) ([14d7e98](14d7e98))

### 🐛 Bug Fixes

* **agent:** execute approved tools concurrently and freeze tickers on finish ([#609](#609)) ([a713306](a713306))

### 💄 Styles

* replace em dashes with hyphens ([91a3746](91a3746))

### 🧹 Maintenance

* **deps:** bump codex 0.133.0 -> 0.135.0 ([#607](#607)) ([86af5fb](86af5fb))
* enable skills by default ([9440593](9440593))
* regenerate config ([991cd77](991cd77))
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.119.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant