Repository navigation
RFC: extending agent-manager without a plugin API (hooks + tools from disk) #819
Replies: 1 comment
|
@ribeirojose thanks for writing this up. hooks.toml: I'd take a PR, as long as it replaces tools.toml: I do want people to add their own tools. I'm planning to move tool definitions to something new and add user plugins on top of it, so adding a tool will go through that instead of a file merged over the builtins. I'll probably open a discussion about plugins soon, here or on Discord. Until then, a new CLI can come in as a PR, like Cursor in #696. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Why
Third-party tools have no place to attach. The MCP server serves agents. It answers what an agent does: spawn, send, read, wait, task. A person who wants to index sessions or count tokens must fork the manager, or poll
sessions --jsonon a timer.A new CLI needs a Go block and a release. #696 adds the Cursor CLI that way. The manager ships 11 tools as blocks in
builtinTools. The block is a TOML document.config.go:230decodes it intomap[string]Tool.Cost tracking needs events, not a feature. The README lists cost tracking as missing. A subscriber needs the start and the end of a turn, and the model that ran the turn. The manager must not own that report.
Proposal
The manager reads two files from the OS configuration directory.
hooks.tomlcarries lifecycle hooks.tools.tomlcarries tool definitions. A lifecycle hook is a command that runs after an event. A tool definition is data about a CLI.One rule keeps the two files away from a plugin system: a hook observes after the effect persists. No third-party code joins status detection or lifecycle ordering. The manager loads no code at run time, and it publishes no ABI.
Related
#478 removed user-editable tool definitions, and this proposal must answer that change. #478 wrote a copy of
defaultConfigtoconfig.tomlon the first run. Every field then stayed at the defaults of that day.backfillToolDefaultsfilled zero values only. The maintainer madeDefault()the only source.tools.tomldoes not copy defaults. It merges over the builtins. It needsoverride = trueto replace a block. A released default still reaches every user who does not override it.What exists
Lifecycleowns the ordered effects for spawn, revive, archive and kill (internal/sessioncmd/lifecycle.go:70).internal/execution/poller.go:507).internal/hooks/hooks.go:48).builtinToolsis the only source of tool definitions (internal/config/builtin.go:3).internal/store/schema.goholds sessions (:7), tasks (:82) and file reservations (:98).config.tomlwas read once, moved intostate.db, and reported in Messages when unreadable (docs/configuration.md:7). A file that the manager reads and makes sure is valid is an established shape here.Design: lifecycle hooks
The file is
<config-dir>/hooks.toml. The manager reads the file at start and on change. The file stays out of Settings, because it is a script surface. Keep the file in a dotfiles repository and review it in a diff. If the file is unreadable, the manager ignores it and writes the reason to Messages.The manager fires each event after the effect persists.
session_startsession_statesession_archivesession_restoresession_killtask_claimtask_finishreview_roundreservation_setThe manager sends one JSON object per line on stdin, then EOF. A subscriber reads lines and needs no framing library. The environment carries
AM_EVENT,AM_SESSION_IDandAM_MANAGER_PID.{"v":1,"event":"session_state","ts":"2026-10-18T14:02:11Z", "session":{"id":"am_7f3c","name":"hospedin-cors","tool":"claude","group":"bleu/hospedin", "directory":"/Users/me/hospedin","worktree":"/Users/me/hospedin-worktrees/cors", "status":"waiting","previous_status":"working","conversation":"0b6f..."}, "manager":{"pid":4812,"version":"0.9.4"}}The manager applies five rules to each hook.
commandinto an argument vector, and never pass the vector to a shell.A
.cmdshim does not work with an argument vector. Pointcommandat a script. A non-zero exit, a timeout and output on stderr go to Messages, with a limit on the rate per event kind.A hook runs after the effect commits. It never runs before the effect and never blocks the effect. The event comes from the effect that owns the state change. A hook that can fail a spawn controls the lifecycle. This proposal rejects that control.
Design: tools.toml
The file is
<config-dir>/tools.toml. It uses thebuiltinToolsschema and merges over the builtins.schema_version = 1.[tools.<id>] extends = "claude"to derive from a builtin, then override single keys.override = trueto replace a whole builtin block. Without that key, the tables merge.status_source = "claude-hooks"stays builtin.agent-manager tools --jsonto list the effective definitions and their source.A typo must not produce a session that never reports status. The error above covers that case.
status_source = "claude-hooks"stays builtin, because hook-fed status depends on the payload shape from Claude, not on a schema that the manager publishes.The #478 objection has a direct answer.
Default()still ships every value. A file only subtracts from a release by overriding named keys. That behaviour is the opposite of the stale copy that #478 removed.Coverage
sessions --jsontask list --jsonInteraction with other work
Claude hooks keep their place. Inbound status stays as it is, and
status_source = "claude-hooks"keeps priority. An outbound event never feeds status back. The new package must not use the namehooks, andinternal/lifecyclehookkeeps the two readable.The MCP server stays separate.
mcpregregisters the agent-facing server into each spawned session. This proposal adds nothing to that server and takes nothing away.A hook runs on the host that owns the row. The host holds
state.dband the pane, and a forwarded event depends on the connection.tools.tomlstays per machine for the same reason: it describes the CLIs that are installed there.Argument vectors are portable. The timeout and the process-group kill need a test on Windows, which is the same gap that #780 names on the inbound side.
Neither file appears in Settings. State that fact in
docs/configuration.md, so that nobody looks for a row that does not exist.Not in scope
.cmdor.ps1shim, and no editor fortools.toml.Do not send message bodies to a hook. A transcript can hold credentials and client material, and the event stream is where that material can leak. The body stays in the store, and the subscriber reads the body from there.
Open questions
session_state, or does the dispatcher? The poller owns the transition. The dispatcher keeps all filtering in one file.T) sessions? This proposal says no, because a terminal has no conversation and shell output is not a turn.task_claim? If not, drop the event and polltask list --json, rather than add a delivery guarantee to the dispatcher.tools.tomlneed a scope per project? A scope per machine stays closer to the model that a tool is an installed CLI.events = []and receive every event, for a debug tap?Where it lives
internal/lifecyclehookfor the dispatcher, the envelope, the timeout and the concurrency limit.internal/sessioncmd/lifecycle.go:70, after each effect commits.internal/execution/poller.go:507, with the debounce.tools --jsonininternal/config/config.go:230.agent-manager hooks --jsonandagent-manager tools --jsonininternal/cli.internal/ui/notices, with a limit on the rate.docs/configuration.mdanddocs/architecture.md.Studied on
mainat 199b32a (2026-10-19). File:line references are to that tree.All reactions