Repository navigation
Description
Problem
The engine/ module ships the tool.Tool / tool.Catalog / tool.Workspace interfaces and engine/tool.NewCatalog(), but no tool bodies. The real Read/Edit/Write/Grep/Glob/Bash implementations live in the root module's internal/adapter/tools, which is not importable.
So an external consumer that embeds engine/agent gets an empty catalog and must reimplement the entire model-facing tool kit from scratch to have a working coding loop. That means re-deriving subtle, security-sensitive invariants we already got right and test hard — most notably Edit's read-before-edit / exact-match / uniqueness-unless-replace_all contract. Two copies of that code drifting apart is exactly the failure mode worth avoiding.
This is squarely in the atrium-convergence theme (make the engine core consumable as a library): engine/adapter/* already advertises itself as "offline test doubles and sane defaults for any engine consumer" (mockllm, memfs, memstore, …). The tool bodies are the same role and belong in the same place.
Scope: the tool bodies ONLY
This issue is deliberately narrow. It graduates the six tool bodies and nothing else, because that is what actually delivers the reuse win (the invariant-heavy code) at the lowest risk.
In scope
- Move the six tool bodies (
read.go,edit.go,write.go,grep.go,glob.go,bash.go) +tools.go(theAll()/Register()/NewBashTool(runner)constructors) intoengine/adapter/tools. These are already engine-clean: their entire non-stdlib import set isengine/session,engine/tool, and five small helpers frominternal/adapter/toolkit(MaxOutputBytes,TruncationMarker,ParseArgs,Schema,Truncate). - Carry only those five helpers with the tools — inline them into the tools package (or a package-private file), NOT a public
toolkitmove. They depend only onengine/session+ stdlib (ParseArgsis a one-line passthrough to the already-exportedsession.ParseArgs). This avoids touching the ~20 unrelatedinternal/sites that use the fulltoolkitgrab-bag. - depguard + DAG entries — one
list-mode: strictblock in.golangci.yml(copy thememfspattern) + one entry inengine/arch/layering_test.go. Bash needsos/execallowed in its block (or a separate block for Bash); everything else staysos-free by going through the injectedtool.Workspace. - Keep the graduated package behind the same
engine/COMPATIBILITY.md"excluded, may change without notice" contract as the other reference adapters.
Out of scope (deliberately)
- The concrete
osfsWorkspace / CommandRunner. The tool bodies are Workspace-agnostic — they take an injectedtool.Workspaceand (for Bash) atool.CommandRunner. The hardenedosfsimplementation (~900 lines) pulls inos,os/exec, thegitenvenv handling, and the secret-scrub cone, which collides with theos-deny convention everyengine/adapter/*block enforces and raises real design questions (does a stripped Workspace ship? does secret-scrub move into the engine module?). None of that is needed to deliver the reuse win. A consumer supplies its own Workspace (validated against the already-exportedfsconformance.Run) and its ownCommandRunner. If a batteries-included reference Workspace is wanted later, that is a separate follow-up with its own design discussion. - The full
internal/adapter/toolkitmigration. It is a shared utility used well beyond tools (mcp,skills,memory,agents); moving the whole thing ripples through ~20 files for no benefit to this issue. Take only the five tool-facing helpers. - The LLM provider adapters (
internal/adapter/anthropic,internal/adapter/openai) — heavy SDK dep closures that should not be forced onto every engine importer. Implementing the two-methodport.LLMProvideris the consumer's job.
What a consumer still owns after this lands
A consumer imports the six tools and never reimplements the correctness-critical bodies. It still supplies (as it should — these are where the sandboxing/credential decisions live):
- a
tool.Workspacescoped to its own root (ordinary file I/O behind a folder boundary; validate againstfsconformance.Run), - a
tool.CommandRunnerfor Bash (a thinos/execwrapper), - a
port.LLMProvider.
Opt-in / opt-out contract (unchanged)
The catalog is caller-assembled, so the graduated kit is purely additive — never mandatory or all-or-nothing:
engine/tool.NewCatalog()returns an empty catalog; the caller registers tools explicitly.- Take all of
tools.All()(+NewBashTool(runner)), take a subset (e.g. read-only, omit Edit/Write/Bash), swap one for a custom implementation (lookup is by name — the caller's tool wins by being the only one registered), or ignore the kit entirely.
The graduation PR + package doc should state this contract explicitly.
Payoff
Engine importers get the invariant-heavy, security-sensitive tool bodies (Edit's contract chief among them) by importing them, instead of re-deriving and testing a second copy that must stay in lockstep with ours — while keeping full control over the Workspace, shell runner, and model credentials.
Activity
jerm-dro commentedon Jul 16, 2026
Will callers still be able to inject their own tools / disable these?
Yes — nothing about this changes the composition model, because the catalog is caller-assembled, not framework-owned:
engine/tool.NewCatalog()returns an empty catalog.catalog.Register(t tool.Tool)(andMustRegister) adds any tool the caller wants — including the caller's own implementations.tools.All()just returns a[]tool.Toolslice; registering it is the caller's choice, tool by tool. There is no implicit/global auto-registration.So after graduating the reference kit, a consumer can:
tools.All()(+NewBashTool(runner)) for a batteries-included coding loop.Editimplementation and skip ours; the engine looks tools up by name viaCatalog.Lookup, so the caller's tool wins by being the only one registered under that name.The reference kit is purely additive: an importable default the caller opts into per-tool, never a mandatory or all-or-nothing bundle. This should be stated explicitly in the graduation PR (and the package doc) so the opt-in/opt-out contract is unambiguous.
[-]Graduate the reference tool kit (toolkit + FS tool bodies) into engine/adapter/tools so engine importers don't reimplement them[/-][+]Graduate the six FS tool bodies into engine/adapter/tools so engine importers don't reimplement them[/+]jerm-dro commentedon Jul 16, 2026
Implementation findings (from a spike; no code landed)
I explored the move end-to-end against the tree before handing off to planning. Key findings that shape the actual PR — several of which the issue body did not anticipate:
1. The
toolspackage can't move wholesale — it must be SPLITinternal/adapter/toolsholds more than the six FS bodies: it also haswebfetch.go,fetchmcpresource.go, andwebsearch.go.websearch.goimportsengine/agent(foragent.FenceUntrusted), and FetchMcpResource is MCP-coupled — so the package as a whole cannot live underengine/adapter/. Only the six FS bodies (Read/Edit/Write/Grep/Glob/Bash) graduate; the three web/MCP tools stay in the root module.Recommended target package name:
engine/adapter/fstools(thetoolsname stays with the root package that keeps the web tools).2. The shared helpers + caps consts are entangled across the split
tools.godefines package-privateparseArgs/truncateBytes/schemawrappers and themaxReadLines/maxGrepMatches/maxGlobResultsconsts. These are used by BOTH the moving FS bodies AND the staying web tools. The move must:fstools(the engine module cannot importinternal/adapter/toolkit).ParseArgsis a one-line passthrough to the already-exportedsession.ParseArgs;Truncate/Schema/utf8RuneStart+MaxOutputBytes/TruncationMarkerare ~30 lines total.toolspackage's own copies for the web tools (they still usetoolkit).MaxOutputBytesmust stay in lockstep withtoolkit.MaxOutputBytes(25 KiB) — note it, since a mixed session applies one cap.engine/session/content.goalready carries a mirror-comment about this constant; addfstoolsto that note.3.
bash.goreferencestoolkitDIRECTLY (not only via wrappers)bashErrorMessageusestoolkit.MaxOutputBytes/toolkit.Truncate/toolkit.TruncationMarkerinline. These become the localfstoolsequivalents. (No other FS body touchestoolkitoutside the three wrappers.) None of the five non-Bash bodies importos; Bash imports neitherosnoros/exec(it runs through the injectedtool.CommandRunner) — so the depguardos-deny that everyengine/adapter/*block carries can stay ON for the wholefstoolspackage. That removes the one anticipated depguard complication.4.
All()/NoFS()/Register()bundle FS + web tools — callers depend on the bundlingToday
tools.All()returns{Read,Edit,Write,Grep,Glob,WebFetch,FetchMcpResource}andNoFS()returns{WebFetch,FetchMcpResource}. ~13 non-test + ~8 test callers usetools.All(),tools.NoFS(),tools.NewBashTool(...), and the concrete types (tools.EditTool{}, etc.) acrossinternal/app(build.go,agentdefs.go,catalog.go),cmd/mecademo,cmd/mecatui/ui,internal/adapter/{forker,server,acp}, and tests.5. Recommended shape: alias shim (least churn, ~0 callers rewritten)
To keep the PR small and additive:
engine/adapter/fstoolsgets the six bodies + inlined helpers + anfstools.All()(the FIVE FS tools, no web) +Register()+NewBashTool.internal/adapter/toolskeeps the web tools and adds a thin alias file re-exporting the FS types (type EditTool = fstools.EditTool,var NewBashTool = fstools.NewBashTool,const BashToolName = fstools.BashToolName, etc.). ItsAll()/NoFS()reassemble fromfstools.All()+ the local web tools, preserving today's exact bundles..golangci.ymlblock.6. Enforcement gates — verified
engine/api/*.txt): tracks only the 7 core packages, NOT adapters. Graduating tools does not touch it — notask api:updateneeded.engine/arch/layering_test.go): treats all ofengine/adapter/*as one forbidden-prefix branch; a newengine/adapter/fstoolsneeds no new entry (auto-covered likememfs).engine-adapter-fstoolslist-mode: strictblock allowing$gostd+engine/session+engine/tool(copy thememfsblock; keep theosdeny).BashToolNameis referenced byinternal/adapter/servercapability probing — the alias must preserve it.Suggested PR steps for the planning agent
git mvthe six bodies →engine/adapter/fstools; rewritepackage tools→package fstools.engine/adapter/fstools/fstools.gowith inlined helpers + caps consts +All()/Register().toolkitfrombash.go; point at local helpers.edit/read/abspath/argkeys/etc — but NOTwebsearch_*/fetchmcpresource_test) tofstools.internal/adapter/tools; re-slim itsAll()/NoFS()/tools.goto web-only + FS aliases.task lint && task test(BOTH modules incl.test:engine-standalone) +go run ./cmd/mecademo.refactor(tools): graduate the six FS tool bodies into engine/adapter/…
JAORMX commentedon Aug 1, 2026
Shipped in PR #277 (merged 2026-07-17) and now released: the
fstoolsgraduation is included in the engine module release engine/v0.7.0 (tag pushed today;go get github.com/stacklok/mecatl/engine@engine/v0.7.0). Closing.refactor(discovery): graduate agent-def + skills discovery into engin…
feat(search): graduate WebSearch tool + providers into engine/adapter (…