Repository navigation
feat(tools): allow registering custom tools in any language - #1372
Conversation
DecodeToolManifest lets a manifest type embed ToolManifest inline and add fields of its own while keeping the strict decode, schema normalization and validation. ValidateArguments moves the MCP argument checks into the shared kernel and also accepts `required` as []string, which a parsed manifest produces and the MCP copy silently skipped.
Each <Name>.yaml manifest in tools.custom_dir (default ~/.infer/tools, env INFER_TOOLS_CUSTOM_DIR) becomes a tool: the built-in manifest schema plus command, timeout and enabled. A call runs the command without a shell, writes the arguments to stdin as JSON and returns stdout. A non-zero exit returns stderr as the error, and a timeout or cancel kills the process group on Unix. Custom tools return their manifest, so modes, approval, !! autocomplete and the plan-mode guard work as for built-ins. A manifest that is invalid, takes a built-in name (even of a disabled tool, case-insensitively) or the MCP_ prefix is skipped with a warning. They register before Markdown subagents load, so a subagent may list them.
Adds docs/custom-tools.md with a shell and a Rust example, and links it from the README, the tools and configuration references, the directory structure and AGENTS.md.
examples/custom-tools ships WordCount (Python, read-only, no approval) and SaveNote (shell, needs approval) with a scenarios.yaml that scripts the embedded mock model, so it runs offline with no API key. The README walks through a tool that runs, one blocked for approval in headless, auto mode and plan mode. An e2e test runs the same scenarios so the example stays true.
Marks examples/** as vendored. The tests/mocks rule named the directory, which gitattributes never applies to the files inside it, so it becomes tests/mocks/** and the counterfeiter fakes finally count as generated.
… add a Taskfile The Taskfile sets the mock model's environment and runs each scenario as one task (word-count, save-note, save-note:auto, save-note:plan, execute, chat), so trying the example is `task <scenario>`. INFER points it at a local build.
Write, Edit, MultiEdit and Delete now refuse any path inside a directory custom tools load from: ~/.infer/tools (or tools.custom_dir), .infer/tools and .agents/tools. The check resolves symlinks and ignores case, so the model cannot write itself a tool that skips approval through a link or another spelling of the path. It applies regardless of tools.sandbox.protected_paths.
…tools Custom tools now also load from the working directory's .infer/tools and .agents/tools and merge with the user's. On a name clash the project tool wins, and .infer/tools wins over .agents/tools. A repository supplies project tools, so every call needs approval whatever the manifest says, readonly mode included, except in auto mode. A project directory that is the user's own directory (infer run from home) stays trusted.
The example now has one tool of each kind: WordCount as a user tool in user-tools/ (via INFER_TOOLS_CUSTOM_DIR) and SaveNote as a project tool in .agents/tools/, which always needs approval. The e2e test copies the project tools into each run's working directory.
internal/tools becomes the home of the tools bounded context, which the agent consumes. Custom tools move there first. The built-in tools and the registry in internal/agent/tools follow in a separate refactor.
|
@infer Can you review this PR? is it ready for merge? use /ponytail:ponytail-review /go /go-concurrency /domain-driven-design /clean-code /clean-architecture |
|
Model: Todos
Pull Request✅ Infer Result: SuccessAll review steps are complete. Here is my final review. Review: PR #1372 - feat(tools): allow registering custom tools in any languageVerdict: ready to merge. I read the full diff and cross-checked the wiring (registry, approval policy, tool contracts, container), and I ran the tests myself: What is done well
ponytail-review (over-engineering scan)Nothing worth cutting. The runtime code is ~350 lines including the formatter glue the Minor notes (non-blocking)
Everything else - the strict manifest decode, name-collision guards, Model: Tokens: 1,582,017 in · 34,738 out · 1,616,755 total (19 requests) Tool calls: 40 total · 100% success rate TracesStatsTriggered by edenreich · Infer Action · OSS |
A tools directory whose absolute path holds glob metacharacters (an unmatched bracket, say) matched nothing and silently loaded zero tools, the one quiet skip in the custom-tools story. List manifests with os.ReadDir so the path is treated as data rather than a pattern, keep missing directories silent and warn on anything else that prevents listing.
…ncel The switch consulted ctx.Err() before the run error, so a call whose process had already exited 0 was reported as timed out when the deadline fired during the pipe-grace window, discarding its captured output. The exit status is now checked first, and a non-zero exit behind exec.ErrWaitDelay is reported as a failure instead of being masked as success.
The loader's user-vs-project identity check compared plain absolute paths while the write-block resolves symlinks and folds case, so a symlinked or case-differing alias of the user's tools dir loaded the same manifests twice and the project load won, flipping the user's own no-approval tools to always-approval. Export config.CanonicalPath, use it in isWithinCustomToolsDir and for the identity check, and test a symlinked project alias of the user dir.
|
@infer Review comments addressed. Can you review this PR again? is it ready for merge? use /ponytail:ponytail-review /go /go-concurrency /domain-driven-design /clean-code /clean-architecture |
|
Model: Todos
Pull Request✅ Infer Result: SuccessAll checks pass and the tree is clean. My review is complete - here it is. Review: ready to mergeVerdict: yes, this PR is ready to merge. I re-read the full diff against Previous review comments - verified addressed
Checks run
Skill assessmentsDomain-driven design: 9/10. Ubiquitous language is consistent across code, docs, tests, and the PR (user tool / project tool / manifest / reserved name). The "project tools always need approval" invariant lives inside the Clean architecture: 9/10 (6/7 rows). Dependencies point inward: Clean code: 9/10. Names carry intent, functions stay small, happy paths un-indented, table-driven tests with Go / go-concurrency: no findings. Modern stdlib throughout ( ponytail-review: Lean already. Ship. Nothing to cut. The MCP validation dedup actually deletes 87 lines, the bounded-context move was correctly deferred to #1373 instead of speculative scaffolding, and every helper in the new package has a caller and a test. Optional polish (non-blocking)
Both are edge-case cosmetics; neither should hold up the merge. Model: Tokens: 1,828,124 in · 27,621 out · 1,855,745 total (22 requests) Tool calls: 50 total · 100% success rate TracesStatsTriggered by edenreich · Infer Action · OSS |
…he pipes past the deadline
|
🎉 This PR is included in version 0.216.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Summary
Closes #1366. Users add tools written in any language with one YAML manifest per tool. A custom tool works like a built-in: the model sees it, it runs through
!!Name(arg="v")andinfer tools execute, and it follows the same agent modes and approval flow.~/.infer/tools/, ortools.custom_dir/INFER_TOOLS_CUSTOM_DIR..infer/tools/and.agents/tools/..infer/tools/wins over.agents/tools/..infer/toolsis the user directory, keeps those tools trusted as user tools.command,timeout(default 30s) andenabled.read_only:or a typo fails loudly. The file name must matchname.require_approvalinheritstools.safety.require_approval.modeshides the tool in plan and readonly, like an MCP tool.require_approval: falsein a project manifest is ignored. Every call asks, even inreadonlymode (which otherwise runs its tools unapproved), except inautomode.CallApproverthat only asks in the tool's own modes, so plan mode still refuses an out-of-mode call with "tool not allowed" rather than an approval request.~/.infer/tools,tools.custom_dir,.infer/toolsor.agents/tools, so the model cannot write itself a tool that skips approval.Config.ValidatePathInSandboxWrite, so it applies regardless oftools.sandbox.protected_paths, including existing configs.parametersbefore the process starts, then written to stdin as one JSON object.tools.max_result_bytescaps what the model sees.MCP_.ToolNames()for this.ToolimplementsManifestTool, so per-mode tool lists, theExecuteToolmode guard,!!autocomplete andStandardApprovalPolicyneed no changes or name lists..infer/agents/*.mdmay list them.tools.enabled: falseturns them off with the other local tools.agentdomain.ValidateArguments, used by MCP and custom tools. It also acceptsrequiredas[]string, which a parsed manifest produces and the old MCP copy silently skipped.examples/toolsruns offline against a tokenless mock model scripted inscenarios.yaml.WordCount(Python user tool, read-only, no approval) andSaveNote(shell project tool in.agents/tools/).task word-count,task save-note(blocked in headless),task save-note:auto,task save-note:plan,task execute,task chat.internal/tools/custom(imported ascustomtools), the start of atoolsbounded context that the agent consumes. Moving the built-in tools and the registry frominternal/agent/toolsinto it is the follow-up [TASK] Refactor the tools into their own bounded context #1373..gitattributesmarksexamples/**as vendored. The existingtests/mocksrule named a directory, which gitattributes never applies to the files inside it, so it becomestests/mocks/**.Commits
refactor(tools):DecodeToolManifest(strict decode for a type embeddingToolManifestinline) andValidateArgumentsin the shared kernel. MCP uses the latter.feat(tools): the custom tools package (loader, runner, process-group kill),tools.custom_dir,ToolNames()per context,mcpdomain.ToolNamePrefix, container wiring.docs:docs/custom-tools.md, plus links from the README, the tools and configuration references, the directory structure and AGENTS.md.style(tools): YAML arrays as block lists in docs and test manifests.ToolsConfig.CustomDir.docs(examples): the tokenless-driven example and an e2e test that runs its scenarios.chore:.gitattributesfor examples and mocks.docs(examples): rename toexamples/toolsand add the Taskfile.feat(tools): refuse file-tool writes into custom tool directories.feat(tools): load project tools from.infer/toolsand.agents/tools, which always need approval.docs(examples): shipSaveNoteas a project tool.refactor(tools): move custom tools frominternal/customtoolstointernal/tools/custom.Testing
internal/tools/custom:MCP_, missing command, negative timeout,enabled: false, missing directory;LLMToolServiceandStandardApprovalPolicy;require_approval: false, and not in auto.config: the write block for.infer/tools,.agents/tools,tools.custom_dir, the directory itself, another spelling and a symlink, while sibling and project files stay writable. The symlink and case cases each fail with their guard removed.agentdomain:ValidateArgumentstable, includingrequiredas[]stringand[]any, andDecodeToolManifestwith an inline extension. Built-in manifests still rejectcommand. The existing MCP tests pass unchanged.TestCustomToolsExampleruns the example's scenarios against the built binary:WordCountruns, the project toolSaveNoteis blocked headless, runs in auto and is refused in plan. The full e2e suite passes.go test -race ./...andtask precommit:runpass. The tool-definitions golden file is unchanged.infer tools execute Writeinto.agents/tools/is refused even with--approved;Read.yamland a manifest withread_only:are skipped with warnings while the built-inReadkeeps working.Not included
internal/agent/toolsintointernal/toolsand cutting its dependency on the agent context is [TASK] Refactor the tools into their own bounded context #1373.infer exportbuilds its own tool registry without custom tools, so their results in exports use the default formatting.automode it can run any command, as it already can for.envfiles..infer/config.yamlis trusted like the user's own and can settools.custom_dir, the Bash allow-list and the approval settings. The docs say to review it in repositories you don't trust.infer plugins, structured or streaming results, and a stdio MCP transport.cli-custom-tools.md, pluscli.mdandmcp.md).