feat(chat): @-mention picker to dispatch sub-agents#15
Open
Mingholy wants to merge 2 commits into
Open
Conversation
Surfaces the agents tier (already composed into each loop's .claude/agents/
on main) as a usable entry point. Re-implemented on current main after the
original stacked CRs (#27509818 compose + #27557638 picker) were stranded by
main's resync onto upstream — the compose half is now upstream, this is just
the picker layer.
- compose.ts: AgentMeta + parseAgentFrontmatter + listLoopAgents(loopId) —
reads the already-composed loopComposedAgentsDir, .md filter, frontmatter
name/description/color, alpha sort; skips dotfiles / broken symlinks.
- index.ts: GET /api/loops/:id/agents (requireAuth + loopExists) → {agents}.
- system-prompt.ts: buildLoopatAppend appends a "## @-mention sub-agents"
block instructing the model to dispatch via the Agent tool when a message
starts with @<name>; omitted when the loop has no agents.
- useLoopRuntime: availableAgents state, fetched once per loopId from the
endpoint (empty array on failure), exposed via LoopRuntimeExtra.
- AgentMention.tsx (new): sister to SlashCommand — opens on leading @, filters
by name+description, inserts `@<name> ` on select, capture-phase key nav.
Empty-state hint when the loop has no composed agents (so @ isn't silent).
- Composer.tsx: mount <AgentMention/> beside <SlashCommand/> (mutually
exclusive by construction).
Tested: server tsc clean; web tsc clean for all touched files (only the
pre-existing CodeEditor.tsx StreamParser error remains on main, unrelated);
vite build OK.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Guard against out-of-bounds crash when filtered list shrinks between renders by clamping selectedIdx in Enter/Arrow handlers. Also reject agent names containing unsafe characters (e.g. backticks) that would break markdown formatting in the system prompt. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
.claude/agents/*.mdas invocable sub-agents via@-mention dropdown@<name>Motivation
Upstream already composes the
agents/directory but has no UI to invoke them. This adds the missing interaction layer.Changes
server/src/compose.ts:AgentMetatype +parseAgentFrontmatter()+listLoopAgents(loopId)server/src/index.ts:GET /api/loops/:id/agentsendpointserver/src/system-prompt.ts: Appends "@-mention sub-agents" block to system promptweb/src/components/chat/AgentMention.tsx(new): Dropdown triggered by leading@, filter + keyboard navweb/src/components/chat/Composer.tsx: Mount<AgentMention/>beside<SlashCommand/>web/src/useLoopRuntime.tsx:availableAgentsstate, fetched once per loopIdTest plan
.claude/agents/researcher.mdwith frontmatter → appears in@dropdown@res→ filtered to "researcher" → select → model dispatches Agent tool@shows empty-state hintScreenshots
Before / After
@-mention dropdown in Composer