Files
coder/coderd
Michael SuchaczandEthan Dickson 97b68e37f9 refactor(coderd/x/chatd): move subagent operations out of tool closures (#28758)
Moves the subagent tools' logic (`spawn_agent`, `wait_agent`,
`message_agent`, `interrupt_agent`, `list_agents`,
`list_subagent_models`) out of large inline closures in `subagent.go`.
Child chat operations become typed `*Server` functions in
`subagent_operations.go` that other code can call, such as the workflow
prototype in #31189. The tools become adapters that parse arguments,
apply defaults and build the JSON.

## Changes

- `subagent_operations.go`: operations take chat IDs, a timeout or a
busy behavior and return plain values. `awaitSubagent` wraps
`awaitSubagentCompletion` with the computer_use desktop recording and a
last status check, and returns the chat, report and recording, a
timeout, or a `*subagentStatusError`. `sendSubagentMessage` and
`interruptSubagent` are main's, unchanged. `listSubagents` returns
unarchived children, most recently updated first. The helpers they call
move from main unchanged.
- `subagent.go`: keeps main's model override resolution. Each tool
parses `chat_id`, applies the wait timeout or list paging defaults,
reads the target chat so errors carry its `type`, and builds the JSON.
`spawnAgent` validates the `spawn_agent` arguments.
- Tool outputs are typed structs whose fields follow sorted key order,
so the JSON the model sees is byte-identical to main's map output.

## Behavior

No intended behavior change. Error strings, tool names, descriptions and
schemas, hook fail-closed handling, the wait loop and recording lifetime
match main. `wait_agent` reads the target chat once more, for the
recording decision.

> Xum (an AI coding agent) rebuilt this PR on behalf of @ibetitsmike.

---------

Co-authored-by: Ethan Dickson <ethanndickson@gmail.com>
2026-11-02 16:25:40 +11:00
..