前端设计
- 作者仓库星标 22
- 许可证 Apache-2.0
- 作者更新于 实时读取
- 作者仓库 unity-explorer
- 领域
- 通用
- 兼容 Agent
-
- Claude Code
- Cursor
- Cline
- Codex
- Windsurf
- Gemini CLI
- +20
- 信任分
- 94 / 100 · 已通过审计
- 作者 / 版本 / 许可
- @decentraland · Apache-2.0
- Token 消耗评级
- 低消耗
- 接入复杂程度
- 需简单配置
- 是否需要外部 API Key
- 不需要
- 兼容的系统
- 未声明(默认跨平台)
- 底层运行要求
- 无特殊要求
- 文件与系统权限
-
- 只读
- 允许写入 / 修改
- Shell 执行
- 网络行为
- 仅限本地
- 安装命令数
- 26 条
档案由构建时根据 SKILL.md 与安装命令自动衍生,可能与作者实际意图存在差异。
需要注意: 未限定 allowed-tools,默认拥有全部工具权限。
---
name: chat-system
description: Chat system — MVP pattern, message bus decorators, commands, auto-translation, encrypted history…
category: 通用
runtime: 无特殊运行时
---
# chat-system 输出预览
## PART A: 任务判断
- 适用问题:通用任务拆解、检查和交付。
- 输入要求:目标材料、限制条件、期望输出和验收方式。
- 证据边界:围绕“Sources / Architecture Overview / Component Map”读取原文规则,不把推断写成作者承诺。
## PART B: 执行结果
- **01** 任务判断:确认你的需求是否属于通用任务拆解、检查和交付,并标出输入、限制和预期结果。
- **02** 执行计划:优先按“Sources / Architecture Overview / Component Map”拆成步骤,说明每一步会读取什么、修改什么、产出什么。
- **03** 交付结果:给出可复制的命令、文件改动、检查清单或内容草稿,并说明如何继续迭代。
- **04** 风险边界:结合 读取文件、写入/修改文件、执行终端命令、主要在本地完成、通常不需要额外 API Key 给出执行前确认项。
## Running Rules
- 读取文件、写入/修改文件、执行终端命令;主要在本地完成;通常不需要额外 API Key。
- 先小样例验证,再放大到真实任务。
- 交付时同时给结果、检查口径和下一步迭代建议。 原文出现了 `/goto`、`/help`、`/version`、`/gotolocal`、`/reloadscene` 这类斜杠命令;如果你的 Agent 支持命令触发,优先用命令开场,再补充目标和边界。
告诉 Agent 目标文件或材料、期望结果、不可改范围、是否允许联网或执行命令。本 Skill 的权限画像是:读取文件、写入/修改文件、执行终端命令。
先用一个小任务确认它会围绕“Sources / Architecture Overview / Component Map”工作;涉及文件或命令时,先看 diff、日志、预览或测试结果。
检查最终产物是否包含明确结果、必要证据和下一步动作;如果输出泛泛而谈,就补充输入、边界和验收标准后重跑。
---
name: chat-system
description: Chat system — MVP pattern, message bus decorators, commands, auto-translation, encrypted history…
category: 通用
source: decentraland/unity-explorer
---
# chat-system
## 什么时候使用
- 把通用方向的常用动作沉淀成 Agent 可调用的技能 适合处理通用任务拆解、检查、交付和复盘,核心价值是把输入、判断、执行、验证和交付边界固定下来,避免 Agent 泛泛回答。 把任务拆成可执行、可检查、可继续迭代的步骤;通常不需要额外…
- 面向通用任务拆解、检查和交付,优先处理能明确输入、步骤和验收标准的工作。
## 需要提供什么
- 目标材料、目录范围、期望结果和不可改动内容。
- 是否允许联网、执行命令、读写文件或调用外部服务。
## 执行规则
- 围绕「Sources / Architecture Overview / Component Map」组织步骤,不把推断写成作者事实。
- 读取文件、写入/修改文件、执行终端命令;主要在本地完成;通常不需要额外 API Key。
- 先跑小样例,确认结果可检查后再扩大任务范围。
## 输出要求
- 给出最终产物、关键证据、验证方式和下一步动作。
- 信息不足时标记 unknown,不编造命令、平台或依赖。 作者原文负责流程事实;仓库文件负责来源和命令;流狐只补充适用场景、限制和质量判断。
skill "chat-system" {
输入层 -> 用户目标 + 目标文件 + 禁止范围 + 验收标准
上下文层 -> Sources / Architecture Overview / Component Map
规则层 -> SKILL.md 触发条件 / 执行顺序 / 输出格式
运行层 -> 无特殊运行时 | 读取文件、写入/修改文件、执行终端命令 | 主要在本地完成
安全层 -> 通常不需要额外 API Key + 小任务验证 + diff / 日志复核
输出层 -> 可复制结果 + 检查清单 + 下一步迭代
} Chat System
Sources
docs/chat.md— Chat architecture (MVP, state machine, commands, services, event bus, auto-translation)docs/chat-emojis.md— Emoji atlas creation with TextMesh Pro, noto-emoji fontdocs/chat-history-local-storage.md— Local encrypted chat history persistence, feature flag control
Architecture Overview
The chat system uses MVP + State Machine + EventBus + Commands:
- View (MonoBehaviour): draw-only; forwards UI events
- Presenter (POCO): listens to View + EventBus, delegates to Commands/Services, updates View
- Model: embodied by Services and data stores (
IChatHistory) - Commands: single-purpose business logic (e.g.,
SendMessageCommand) - Services: long-lived shared state or I/O boundaries (history, member lists, input blocking)
- EventBus: decoupled comms via
ChatEvents(no tight coupling between Presenters) - State Machine:
ChatStateMachinecontrols top-level UI mode; replaces boolean soup - Composition root:
ChatPluginwires Views, Presenters, Commands, Services, and State Machine
Component Map
| Layer | Key Classes |
|---|---|
| Composition | ChatPlugin, ChatMainSharedAreaController |
| Presenters | ChatPanelPresenter, ChatTitlebarPresenter, ChatInputPresenter, ChatMessageFeedPresenter, ChatChannelsPresenter, ChatMemberListPresenter |
| Commands | SendMessageCommand, SelectChannelCommand, InitializeChatSystemCommand, GetMessageHistoryCommand, ResolveInputStateCommand, ~20 more |
| Services | CurrentChannelService, ChatHistoryService, ChatMemberListService, ChatInputBlockingService, ChatContextMenuService, ChatWorldBubbleService |
| State Machine | ChatStateMachine with Init, Default, Focused, Members, Minimized, Hidden states |
Message Send Flow
ChatInputViewraisesonSubmit("Hello")ChatInputPresentercallsSendMessageCommand- Command pulls active channel from
CurrentChannelService, callsIChatMessagesBus - Bus echoes
MessageAddedlocally (optimistic UI) ChatHistoryServicepersists toIChatHistoryChatMessageFeedPresentermaps viaCreateMessageViewModelCommandand updates View
Message Bus Decorator Chain
IChatMessagesBus is wrapped in decorators, each adding a concern. The chain is composed in DynamicWorldContainer.
Decorator Responsibilities
| Decorator | Role |
|---|---|
MultiplayerChatMessagesBus |
Core transport: sends via LiveKit pipes (Island/Scene/Chat), receives from subscribed pipes, deduplicates, rate-limits, buffers nearby messages |
SelfResendChatMessageBus |
On Send(), also fires MessageAdded for the sender's own message (optimistic local echo) |
IgnoreWithSymbolsChatMessageBus |
Filters messages containing forbidden control characters (\u2410, \u2406, \u2411) |
CommandsHandleChatMessageBus |
Intercepts /-prefixed messages, parses command + args, dispatches to IChatCommand, sends system response |
Interface
public interface IChatMessagesBus : IDisposable
{
event Action<ChatChannel.ChannelId, ChatChannel.ChatChannelType, ChatMessage> MessageAdded;
void Send(ChatChannel channel, string message, ChatMessageOrigin origin, double timestamp);
}
Each decorator wraps origin.Send() and forwards origin.MessageAdded events, adding its own logic before or after.
Chat Command Pattern
Interface
public interface IChatCommand
{
string Command { get; }
string Description { get; }
bool DebugOnly => false;
bool ValidateParameters(string[] parameters) => parameters.Length == 0;
UniTask<string> ExecuteCommandAsync(string[] parameters, CancellationToken ct);
}
Existing Commands
| Command | Class | Debug? |
|---|---|---|
/goto <x,y|random|crowd|world> |
GoToChatCommand |
No |
/help |
HelpChatCommand |
No |
/version |
VersionChatCommand |
No |
/gotolocal <x,y> |
GoToLocalChatCommand |
Yes |
/reloadscene |
ReloadSceneChatCommand |
Yes |
/debugpanel |
DebugPanelChatCommand |
Yes |
/showentity <id> |
ShowEntityChatCommand |
Yes |
/logs <category> <level> |
LogsChatCommand |
Yes |
/logmatrix |
LogMatrixChatCommand |
Yes |
/rooms |
RoomsChatCommand |
Yes |
/loadpx <urn> |
LoadPortableExperienceChatCommand |
Yes |
/killpx <urn> |
KillPortableExperienceChatCommand |
Yes |
/appargs |
AppArgsChatCommand |
Yes |
Commands are registered in DynamicWorldContainer as IReadOnlyList<IChatCommand> and looked up by name in a dictionary.
Input State Machine
ChatStateMachine manages 6 UI states via MVCStateMachine<ChatState>. Each state class contains only logic relevant to that state.
State Transitions
Init --> Default (on view show)
Default --> Focused (click inside / focus requested)
Default --> Minimized (close requested)
Default --> Members (toggle members)
Focused --> Default (click outside)
Focused --> Minimized (close requested)
Focused --> Members (toggle members)
Members --> Default (click outside)
Members --> Focused (close/back/toggle)
Minimized --> Focused (focus requested / minimize toggle)
Hidden <-- (SharedSpaceManager hides chat when other panels open)
Hidden --> Default (SharedSpaceManager restores chat)
All states inherit ChatState which provides virtual no-op methods: OnClickOutside, OnClickInside, OnCloseRequested, OnFocusRequested, OnMinimizeRequested, OnToggleMembers, OnPointerEnter, OnPointerExit. States override only the transitions they handle.
Auto-Translation
Translation is orchestrated by TranslationService with modular components:
| Component | Role |
|---|---|
ITranslationService |
Central orchestrator for auto and manual translation |
ITranslationProvider (DclTranslationProvider) |
External API adapter |
IMessageProcessor (ChatMessageProcessor) |
Tokenizes complex messages, protects non-translatable parts |
IConversationTranslationPolicy |
Decides if auto-translate applies (global flag + per-conversation toggle) |
ITranslationCache (InMemoryTranslationCache) |
Prevents redundant API calls; capacity configured via ChatConfig.TranslationCacheCapacity (default 200) |
ITranslationMemory (InMemoryTranslationMemory) |
Tracks per-message translation state (Original, Pending, Success, Failed); capacity 200 |
Configuration (ChatConfig ScriptableObject)
[field: SerializeField] public int TranslationMaxRetries { get; set; } = 1;
[field: SerializeField] public float TranslationTimeoutSeconds { get; set; } = 10.0f;
public int TranslationMemoryCapacity = 200;
public int TranslationCacheCapacity = 200;
Flow
TranslationService.ProcessIncomingMessage()checksIConversationTranslationPolicy- Creates
MessageTranslationwithPendingstate inITranslationMemory - Publishes
TranslationEvents.MessageTranslationRequested - Checks
ITranslationCachefor existing result - Runs
RequiresProcessing()-- if text has TMP tags, emojis, dates, or slash commands, usesIMessageProcessor(tokenize, protect, batch-translate); otherwise callsITranslationProviderdirectly - Stores result in cache + memory, publishes
TranslationEvents.MessageTranslated - On failure, sets
Failedstate, publishesTranslationEvents.MessageTranslationFailed
Concurrency: per-sender serialization via leader/follower gates, global cap of 10 in-flight translations.
Encrypted History
Feature flag: explorer-alfa-chat-history-local-storage. Core classes in Explorer/Assets/DCL/Chat/History/.
Storage Layout
{persistentDataPath}/c/
{Base64(AES(walletAddress))}/ <-- per-account folder
{Base64(AES("UserConversationSettings"))} <-- encrypted JSON: open channels + order
{Base64(AES(channelId))} <-- encrypted CSV per conversation
Key Behaviors
- Per-account isolation: wallet address is the encryption key; folder name is
Base64(AES(address)) - Lazy file I/O: files stay open for 5 seconds after last write, then auto-close
- Background processing: message queue processed on a thread pool via
UniTask.RunOnThreadPool - Rehydration: on first DM message, snapshots session messages, loads history from disk, replays session tail to avoid data loss
- Nearby excluded: only
ChatChannelType.USERconversations are persisted
Detailed Reference
For detailed code examples, see reference.md.
Cross-References
- mvc-and-ui-architecture -- MVC controller pattern,
SharedSpaceManagerpanel coordination - web-requests --
IWebRequestControllerused byDclTranslationProviderandGoToChatCommandfor API calls - feature-flags-and-configuration --
FeatureFlagsStrings.CHAT_HISTORY_LOCAL_STORAGEgates history;FeaturesRegistrygates rate limiting and message buffering
先判断是否适合
作者设计意图
作者的方法与取舍
边界和复核