Replaces the 20-parameter `executeTools` and the 15-parameter
`executeSingleTool` in `chatloop` with methods on an unexported
`toolBatch`. `newToolBatch` builds it once from
`ExecuteLocalToolsOptions`, `run` replaces `executeTools`, and `runOne`
replaces `executeSingleTool`. The 12 internal test calls set only the
options they use instead of up to 20 positional arguments.
It also deletes two copies:
- `executeTools` filtered out provider-executed calls that
`ExecuteLocalTools` had already removed. Only the `ExecuteLocalTools`
filter remains.
- The `runOne` metric defer repeated the body of
`recordToolResultMetrics`. It now calls that function.
## Why it is safe
- `newToolBatch` builds the tool, runner, and metadata maps with the
lines `executeTools` used, and the byte budget as `ExecuteLocalTools`
did. `run` drops the empty-batch returns: `ExecuteLocalTools` returns
before it when no local call is left.
- `recordToolResultMetrics` labels by `result.ToolName`, which `runOne`
sets to `tc.ToolName` and never changes. It skips a nil `Metrics`.
Production never passes one, because `ExecuteLocalTools` sets
`NopMetrics()` first; only the direct test calls, which omit `Metrics`,
use that path.
- With the duplicate filter gone, removing the remaining
`ProviderExecuted` filter fails
`TestExecuteLocalTools_ProviderToolRunner` (#30937). The other four
mutants from #30937 still fail it here.
- `git grep 'executeTools\|executeSingleTool'` finds one comment, in
`chatd_test.go`, which this PR updates.
## Review focus
The metric defer stays a closure so that it reads `result` when `runOne`
returns.
## Validation
- `go test -race -count=1 ./coderd/x/chatd/chatloop/` passes on #30937
and here, including the 16 tests that reach this code:
`TestExecuteTools*` (5), `TestExecuteSingleTool_*` (5),
`TestExecuteLocalTools*` (6).
- `TestActiveServer_ToolErrorRecordsMetric`,
`TestActiveServer_ToolExecutionAndPolicy`, and
`TestProcessChatPanicRecovery` in `./coderd/x/chatd/` pass on #30937 and
here.
- `golangci-lint run ./coderd/x/chatd/chatloop/...` reports 0 issues,
and the pre-commit hook passed.
## Stack
This stack replaces the 20-parameter `executeTools` and the 15-parameter
`executeSingleTool` in `chatloop` with methods on one `toolBatch` type,
and resolves tool name aliases in one place. Production behavior does
not change.
1. #30937 Cover provider tool runners in `ExecuteLocalTools`
2. #30938 Replace `executeTools` and `executeSingleTool` with
`toolBatch`
3. #30939 Resolve tool name aliases in one `toolBatch` method
> Xum, an AI agent, opened this PR for @ibetitsmike and wrote this
description.