Repository navigation
refactor(tools): graduate the six FS tool bodies into engine/adapter/fstools (#269) - #277
Merged
Merged
Conversation
…fstools (#269) Move the correctness/security-critical tool bodies — Read, Edit, Write, Grep, Glob, and the optional Bash — into the importable engine module as engine/adapter/fstools, so external consumers of engine/agent get them, and Edit's read-before-edit / exact-match / uniqueness invariants, by import rather than re-derivation. The bodies depend only on engine/session + engine/tool (+ the injected tool.Workspace/CommandRunner); the toolkit dependency in bash.go is replaced by locally-inlined MaxOutputBytes/ TruncationMarker/truncate helpers. The root internal/adapter/tools package re-exports the tool types, NewBashTool, and BashToolName via a thin alias shim (alias.go) and keeps the host-coupled web/MCP tools (WebFetch, WebSearch, FetchMcpResource). tools.All()/NoFS() preserve the exact prior bundles and order, so every existing caller (internal/app, cmd/mecademo, server) compiles unchanged. Tests: the FS-body behavior tests + argkeys drift-guard move into fstools (offline, memfs-only). The mixed FS+web catalog-shape tests stay in root. abspath_tools_test.go / read_readroots_test.go stay in root because they import internal/adapter/osfs, which the engine module must not reach. Also: engine-adapter-fstools strict depguard block; MaxOutputBytes lockstep mirror-comment in engine/session/content.go; COMPATIBILITY.md + AGENTS.md reference-adapter inventory updates. Verified: engine-standalone (GOWORK=off) build+test, api:check, root go test ./..., docs:check, and mecademo offline session all pass. llms.txt regenerates byte-identical. Co-Authored-By: Claude Opus 4.8 <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR refactors the tool implementation layout by moving the core filesystem tool bodies (Read/Edit/Write/Grep/Glob + optional Bash) out of the root module and into the importable engine module as engine/adapter/fstools, while keeping the root’s internal/adapter/tools package as a composition layer for host-coupled tools and backwards-compatible re-exports.
Changes:
- Introduces
engine/adapter/fstoolsas the canonical, importable implementation for FS tool bodies (plus associated unit tests). - Updates
internal/adapter/toolsto composefstools.All()with host-only tools, and re-export FS tool types/functions via aliases. - Updates guardrails/docs/config to reflect the new adapter (
engine/COMPATIBILITY.md,AGENTS.md,.golangci.yml) and relocates tests accordingly.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/adapter/tools/tools.go | Switches catalog composition to append(fstools.All(), ...) and updates package-level documentation. |
| internal/adapter/tools/tools_test.go | Narrows tests to verify the composed catalog shape (FS+web/MCP) while FS body tests move to engine module. |
| internal/adapter/tools/alias.go | Adds type/function/const re-exports for migrated FS tool bodies. |
| engine/adapter/fstools/fstools.go | New package entrypoint: constants, bundle helpers (All, Register), and shared helpers (truncation/schema/args). |
| engine/adapter/fstools/fstools_test.go | New unit tests covering FS tool behavior inside the engine module. |
| engine/adapter/fstools/read.go | Renames/moves Read tool body into fstools package. |
| engine/adapter/fstools/edit.go | Renames/moves Edit tool body into fstools package. |
| engine/adapter/fstools/write.go | Renames/moves Write tool body into fstools package. |
| engine/adapter/fstools/grep.go | Renames/moves Grep tool body into fstools package. |
| engine/adapter/fstools/glob.go | Renames/moves Glob tool body into fstools package. |
| engine/adapter/fstools/bash.go | Moves Bash tool body into fstools and removes dependency on root internal/adapter/toolkit. |
| engine/adapter/fstools/argkeys_test.go | Moves the arg-key drift guard into the new fstools package. |
| engine/session/content.go | Updates documentation to reference the new fstools output cap as a lockstep constant. |
| engine/COMPATIBILITY.md | Adds fstools to the “reference adapters may change” section and documents its opt-in composition model. |
| AGENTS.md | Updates the reference-adapter inventory to include fstools. |
| .golangci.yml | Adds a strict depguard block for engine/adapter/fstools. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…hTool as a func - engine/session/content.go + engine/adapter/fstools/fstools.go: correct the output-cap comments. MaxToolResultTextBytes (25 KiB = 25,600) is a domain-level upper bound on ANY tool-result text block; the adapter caps (fstools/toolkit.MaxOutputBytes = 25,000) sit strictly under it. Only those two are byte-identical — the ~600-byte headroom to the domain bound is deliberate. Drop the misleading "keep the three in lockstep" wording. - internal/adapter/tools/tools.go: clarify that WebSearch (like Bash) is NOT in All()/NoFS() — it needs a search provider and is registered separately via NewWebSearchTool(provider). - internal/adapter/tools/alias.go: re-export NewBashTool as a wrapper function instead of a reassignable package var, so no other package can swap the constructor. Co-Authored-By: Claude Opus 4.8 <[email protected]>
jerm-dro
marked this pull request as ready for review
July 17, 2026 20:54
JAORMX
approved these changes
Jul 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Graduates the six correctness/security-critical filesystem tool bodies — Read, Edit, Write, Grep, Glob, and the optional Bash — out of the host-repo
internal/adapter/toolsand into the importable engine module asengine/adapter/fstools(issue #269). External consumers ofengine/agentnow get these tools — and Edit's read-before-edit / exact-match / uniqueness invariants — by import, not by re-deriving them.How
engine/adapter/fstools(new): the six bodies +fstools.gowithAll()/Register()/NewBashTool, inlined helpers (parseArgs→session.ParseArgs,truncate/truncateBytes/utf8RuneStart), and theMaxOutputBytes/TruncationMarker/caps consts. Depends only onengine/session+engine/tool(+ the injectedtool.Workspace/CommandRunner) — neveros. Bash's oldtoolkitdependency is replaced by the local consts.internal/adapter/toolsre-slimmed:alias.gore-exports the tool types,NewBashTool, andBashToolName; the package keeps the host-coupledWebFetch/WebSearch/FetchMcpResource.tools.All()=append(fstools.All(), WebFetchTool{}, FetchMcpResourceTool{})— exact prior bundle and order preserved, so every caller (internal/app,cmd/mecademo,server) compiles unchanged. Zero caller rewrites.argkeysdrift-guard move intofstools(offline, memfs-only). The mixed FS+web catalog-shape tests stay in root.abspath_tools_test.go/read_readroots_test.gostay in root — they importinternal/adapter/osfs, which the engine module must not reach.engine-adapter-fstoolsstrict depguard block;MaxOutputByteslockstep mirror-comment inengine/session/content.go;COMPATIBILITY.md+AGENTS.mdreference-adapter inventory updates.Verification
task test:engine-standalone(GOWORK=off) — the definitive proof the moved bodies carry no strayinternal/importtask api:check(engine public surface untouched — an adapter isn't a tracked core package; notask api:updateneeded)go test ./...; engine tests pass GOWORK-on and offtask docs:checkstrict link gate (0 broken);llms.txtregenerates byte-identical (prose-only doc edits)go run ./cmd/mecademoprints the full offline lifecycle with the graduated Read/Write bodies executing through real compositionfstools+ roottoolspackages lint clean (0 issues)🤖 Generated with Claude Code