Skip to content

feat(ai): AIChat 输入框支持 @ 符号选择专家 Agent#261

Merged
hrygo merged 15 commits into
mainfrom
feat/259-agent-mention-popover
Feb 19, 2026
Merged

feat(ai): AIChat 输入框支持 @ 符号选择专家 Agent#261
hrygo merged 15 commits into
mainfrom
feat/259-agent-mention-popover

Conversation

@hrygo

@hrygo hrygo commented Feb 18, 2026

Copy link
Copy Markdown
Owner

Summary

实现 AIChat 输入框的 @ 符号触发专家 Agent 选择弹窗功能,并修复 ParrotSelfCognition 配置问题。

Resolves #259

Changes

新功能

  • AgentMentionPopover.tsx: 新增专家代理选择弹窗组件

    • 键盘导航(↑↓ + Enter + Esc)
    • 鼠标点击选择
    • 主题色区分(灰灰 slate / 时巧 cyan / 通才 amber / 灵光 violet)
    • Portal 渲染避免 z-index 问题
    • 从 API 动态获取代理列表
  • ChatInput.tsx: 集成 @ 检测逻辑

    • 检测 @ 输入并触发弹窗
    • 支持头部/尾部位置插入
    • 处理选择后的文本插入
  • useParrotsList.ts: 新增 Hook,从 API 获取可提及的专家代理列表

  • agentMention.ts: 新增工具函数

    • 解析消息中的 @ 提及
    • 判断光标位置
    • 插入代理提及

Bug 修复

  • ParrotSelfCognition: 修复 FavoriteTools 和 Capabilities 与实际工具不匹配的问题
    • FavoriteTools 现在列出实际工具名(如 memo_search, schedule_add
    • Capabilities 使用中文描述,与 YAML 配置一致
    • General 正确使用空的 FavoriteTools(纯 LLM,无工具)

性能优化

  • ChatHandler 缓存: 避免每次请求重新创建 ChatRouter、Orchestrator 等组件
  • GeekMode/EvolutionMode 优化: 跳过不必要的上下文构建(直接 CLI 执行)

重构

  • 移除已废弃的 AMAZING/CREATIVE 兼容代码
  • 统一使用 GENERAL 和 IDEATION 代理类型

Test plan

  • make check-all 通过
  • 输入框 @ 触发 Agent 选择弹窗
  • 支持头部/尾部位置插入
  • 支持中文名 (@灰灰) 和英文名 (@memo) 匹配
  • 键盘导航(上下键 + Enter)正常工作
  • ListParrots API 返回正确的 FavoriteTools 和 Capabilities
  • GeekMode 不再显示不必要的上下文构建日志

Screenshot

┌─────────────────────────────────────────┐
│  🦜 选择专家代理                         │
├─────────────────────────────────────────┤
│  📝 灰灰 - 笔记搜索专家                  │
│  📅 时巧 - 日程管理专家                  │
│  🤖 通才 - 通用智能代理                  │
│  💡 灵光 - 创意生成专家                  │
├─────────────────────────────────────────┤
│  ↑↓ 选择 · Enter 确认 · Esc 关闭         │
└─────────────────────────────────────────┘

🤖 Generated with Claude Code

@hrygo

hrygo commented Feb 18, 2026

Copy link
Copy Markdown
Owner Author

Code review

Found 3 issues:

  1. Invalid ParrotAgentType values using unsafe type assertions (.claude/rules/code-style.md requires proper TypeScript usage)

The code uses type assertions to create ParrotAgentType values that don't exist in the enum:

通才: "GENERAL" as ParrotAgentType,
灵光: "INSIGHT" as ParrotAgentType,

The ParrotAgentType enum only contains: AUTO, MEMO, SCHEDULE, AMAZING, GEEK, EVOLUTION. This bypasses TypeScript's type safety and will cause runtime issues when these values are used with the backend API.

// 通才 - 通用助手(需要后端支持)
通才: "GENERAL" as ParrotAgentType,
general: "GENERAL" as ParrotAgentType,
// 灵光 - 创意助手(正在创建)
灵光: "INSIGHT" as ParrotAgentType,
insight: "INSIGHT" as ParrotAgentType,
创意: "INSIGHT" as ParrotAgentType,

  1. Hardcoded Chinese text bypassing i18n (.claude/rules/i18n.md says "禁止硬编码:所有 UI 文本使用 t('key')")
<kbd>Enter</kbd>  ·
<kbd>{sendShortcut}</kbd> 

Non-Chinese users will see untranslated text. The code correctly uses t() on line 326-327 but bypasses it on line 337-338.

<div className="flex items-center justify-end mb-2">
<span className="hidden sm:inline text-xs text-muted-foreground">
<kbd className="px-1 py-0.5 bg-muted rounded">Enter</kbd> 发送 ·
<kbd className="px-1 py-0.5 bg-muted rounded ml-1">{sendShortcut}</kbd> 换行
</span>
</div>

  1. Dynamic Tailwind classes may not work with Tailwind v4 (CLAUDE.md says "常见陷阱: max-w-md 等语义类 | Tailwind v4 解析为 ~16px")
`text-${color.primary}-700 dark:text-${color.primary}-200`

Template literal class names are not detected by Tailwind v4's JIT compiler, resulting in missing styles. The project explicitly uses explicit values elsewhere to avoid this.

{/* 信息 */}
<div className="flex-1 min-w-0">
<div className={cn("font-medium text-sm truncate", `text-${color.primary}-700 dark:text-${color.primary}-200`)}>
@{agent.displayName || agent.name}
</div>
<div className="text-xs text-muted-foreground truncate">{agent.description}</div>

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

hotplex-ai and others added 5 commits February 18, 2026 19:27
Implement UI component for mentioning expert agents (灰灰, 时巧, 通才, 灵光)
via @ symbol in chat input. Features include:

- AgentMentionPopover component with keyboard navigation (↑↓ + Enter + Esc)
- Dynamic agent list from API with filtering support
- Theme-colored agent items (slate/cyan/amber/violet)
- Portal rendering for proper z-index handling
- Integration with ChatInput for @ detection and text insertion

Files:
- AgentMentionPopover.tsx: Main popover component
- ChatInput.tsx: Integration with @ detection logic
- useParrotsList.ts: Hook for fetching mentionable agents
- agentMention.ts: Utility functions for parsing and insertion
- i18n: Added translations for general and insight agents

Refs #259

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove invalid ParrotAgentType type assertions (GENERAL, INSIGHT)
- Remove support for unimplemented agents (通才, 灵光) with TODO
- Replace hardcoded Chinese text with i18n t() calls
- Replace dynamic Tailwind classes with static classes for v4 JIT

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add general (通才) mapped to AMAZING type
- Add ideation (灵光) with IDEATION type (pending backend support)
- Update color themes for both agents
- Update MENTIONABLE_NAMES list

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Breaking changes:
- Rename AGENT_TYPE_AMAZING to AGENT_TYPE_GENERAL in proto
- Update all frontend ParrotAgentType.AMAZING to GENERAL
- Update all backend AMAZING references to GENERAL
- Remove AGENT_TYPE_CREATIVE (reserved for future use)

Agent naming:
- memo -> 灰灰 (笔记助手)
- schedule -> 时巧 (日程管理)
- general -> 通才 (通用助手)
- ideation -> 灵光 (创意助手, pending backend support)

Cleanup:
- Remove deprecated proto/api/v1/*.pb.go files (use proto/gen instead)
- Update agent mention mapping to use GENERAL

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add bounds check for selectedIndex in scroll effect to prevent null pointer
- Fix race condition in keyboard handler using ref for filteredAgents
- Fix event listener cleanup with isMounted flag to prevent memory leak
- Add AMAZING to legacy mapping for backward compatibility
- Update TODO comment to NOTE for IDEATION placeholder
- Fix shouldTriggerMentionPopover logic to return false for invalid positions

Refs #259

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@hrygo hrygo force-pushed the feat/259-agent-mention-popover branch from 4e4f0d9 to 3c85724 Compare February 18, 2026 11:29
@hrygo

hrygo commented Feb 18, 2026

Copy link
Copy Markdown
Owner Author

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

Reviewed:

  • CLAUDE.md adherence
  • Bug detection (shallow scan)
  • Git history context
  • Previous PR comments
  • Code comment compliance

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

hotplex-ai and others added 10 commits February 18, 2026 21:28
… agents

Remove non-mentionable agent mappings (auto, geek, evolution, amazing)
from formatAgentMention. Only keep agents that can be @ mentioned:
memo, schedule, general, and ideation (placeholder).

Refs #259

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Backend:
- Add AGENT_TYPE_IDEATION to proto enum (value 5)
- Add IDEATION routing and default title mapping
- Remove legacy CREATIVE/AMAZING/DEFAULT mappings

Frontend:
- Add ParrotAgentType.IDEATION enum value
- Add IDEATION theme (violet), sound effects, catchphrases, behaviors
- Add IDEATION to PARROT_AGENTS metadata
- Remove placeholder comment from agentMention.ts
- Update AIChatContext with IDEATION default title

i18n:
- Add chat.default.general and chat.default.ideation keys
- Remove deprecated chat.default.amazing key

Refs #259

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove GENERAL from EXCLUDED_AGENT_TYPES in useParrotsList
- Add IDEATION to AGENT_TYPE_MAP
- Update isMentionable to include GENERAL and IDEATION
- Remove outdated comment about ideation pending backend support

Fixes issue where @ mention popover showed "未找到匹配的专家"

Refs #259

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add AGENT_TYPE_IDEATION to agentTypes list
- Add IDEATION case to getParrotSelfCognition
- Add IDEATION case to getParrotNameByAgentType

Fixes issue where @ mention popover showed "未找到匹配的专家"
because ListParrots API did not include IDEATION agent.

Refs #259

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Limitations are not enumerable as "cannot do" is infinite.
Following unified architecture principles, remove this field
from all parrot self-cognition definitions.

Refs #259

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Clean up legacy naming:
- Backend: Update schedule self-cognition to use "时巧 - 日程管理专家"
- Frontend: Update AISuggestionCards aria-label and badge text
- Proto: Update comment examples to use correct names

Legacy names removed:
- "金刚" → "时巧" (schedule agent)
- "creative", "amazing" → "general", "ideation" (proto comments)

Refs #259

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- FavoriteTools now lists actual tool names matching config/parrots/*.yaml
- Capabilities use Chinese descriptions matching self_description.capabilities
- General agent correctly has empty FavoriteTools (pure LLM, no tools)
- Memo emoji changed from 🦜 to 📝 for consistency
- Removed deprecated AMAZING/CREATIVE compatibility mapping (data cleared)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Cache chatHandler in AIService with lazy initialization (getChatHandler)
- Avoid creating ChatRouter, Orchestrator, etc. on every request
- Skip context building for GeekMode and EvolutionMode (direct CLI execution)
- Reduces unnecessary initialization logs and improves performance

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The name field should be a programmatic identifier (memo, schedule, etc.),
not a display name. Display names are available via SelfCognition.Title.

This fixes the "未找到匹配的专家" error in agent mention popover,
where frontend filters by English names but API returned Chinese.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@hrygo hrygo merged commit c922a93 into main Feb 19, 2026
10 checks passed
@hrygo hrygo deleted the feat/259-agent-mention-popover branch February 19, 2026 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(ai): AIChat 输入框支持 @ 符号选择专家 Agent

2 participants