Skip to content

refactor(tools): graduate the six FS tool bodies into engine/adapter/fstools (#269) - #277

Merged
JAORMX merged 2 commits into
mainfrom
jerm-dro/01KXRMBSRPBBTE028GZE7PNNHQ
Jul 18, 2026
Merged

JAORMX merged 2 commits into
mainfrom
jerm-dro/01KXRMBSRPBBTE028GZE7PNNHQ

Conversation

@jerm-dro

Copy link
Copy Markdown
Contributor

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/tools and into the importable engine module as engine/adapter/fstools (issue #269). External consumers of engine/agent now 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.go with All()/Register()/NewBashTool, inlined helpers (parseArgs→session.ParseArgs, truncate/truncateBytes/utf8RuneStart), and the MaxOutputBytes/TruncationMarker/caps consts. Depends only on engine/session + engine/tool (+ the injected tool.Workspace/CommandRunner) — never os. Bash's old toolkit dependency is replaced by the local consts.
  • internal/adapter/tools re-slimmed: alias.go re-exports the tool types, NewBashTool, and BashToolName; the package keeps the host-coupled WebFetch/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.
  • Tests: FS-body behavior tests + the 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 — they import internal/adapter/osfs, which the engine module must not reach.
  • Supporting: engine-adapter-fstools strict depguard block; MaxOutputBytes lockstep mirror-comment in engine/session/content.go; COMPATIBILITY.md + AGENTS.md reference-adapter inventory updates.

Verification

  • ✅ task test:engine-standalone (GOWORK=off) — the definitive proof the moved bodies carry no stray internal/ import
  • ✅ task api:check (engine public surface untouched — an adapter isn't a tracked core package; no task api:update needed)
  • ✅ root go test ./...; engine tests pass GOWORK-on and off
  • ✅ task docs:check strict link gate (0 broken); llms.txt regenerates byte-identical (prose-only doc edits)
  • ✅ go run ./cmd/mecademo prints the full offline lifecycle with the graduated Read/Write bodies executing through real composition
  • fstools + root tools packages lint clean (0 issues)

Note: a full task lint reports pre-existing issues in files not touched by this PR (surfaced by a newer local golangci-lint/gosec); the changed packages are clean.

🤖 Generated with Claude Code

…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]>

Copilot AI 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.

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/fstools as the canonical, importable implementation for FS tool bodies (plus associated unit tests).
  • Updates internal/adapter/tools to compose fstools.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.

Comment thread engine/session/content.go Resolved
Comment thread engine/adapter/fstools/fstools.go Resolved
Comment thread internal/adapter/tools/tools.go Resolved
Comment thread internal/adapter/tools/alias.go Resolved
…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
jerm-dro requested a review from JAORMX July 17, 2026 20:54
@jerm-dro
jerm-dro marked this pull request as ready for review July 17, 2026 20:54
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.

3 participants