chat-system
- Repo stars 22
- License Apache-2.0
- Author updated Live
- Author repo unity-explorer
- Domain
- Other
- Compatible agents
-
- Claude Code
- Cursor
- Cline
- Codex
- Windsurf
- Gemini CLI
- +20
- Trust score
- 94 / 100 · audit passed
- Author / version / license
- @decentraland · Apache-2.0
- Token usage
- Lean
- Setup complexity
- Guided setup
- External API key
- Not required
- Operating systems
- Unspecified (assume cross-platform)
- Runtime requirements
- No special requirements
- Permissions
-
- Read-only
- Write / modify
- Shell exec
- Network behavior
- Local-only
- Install commands
- 26 variants
Profile is derived at build time from SKILL.md and install vectors. Subject to drift from author intent.
Heads up: 未限定 allowed-tools,默认拥有全部工具权限。
---
name: chat-system
description: Chat system — MVP pattern, message bus decorators, commands, auto-translation, encrypted history…
category: other
runtime: no special runtime
---
# chat-system output preview
## PART A: Task fit
- Use case: Chat system — MVP pattern, message bus decorators, commands, auto-translation, encrypted history, state machine. Use when adding chat commands, modifying message flow, or working with chat services..
- Inputs: target material, constraints, expected output, and acceptance criteria.
- Evidence boundary: follow “Sources / Architecture Overview / Component Map” and do not present inference as author intent.
## PART B: Execution result
- **01** The card summarizes the use case; runtime output centers on “Chat system — MVP pattern, message bus decorators, commands, auto-translation, encrypted history, state machine. Use when adding chat commands, modifying message flow, or working with chat services.”.
- **02** When the source has headings, the agent prioritizes “Sources / Architecture Overview / Component Map” so the result follows the author’s structure.
- **03** Typical output includes task judgment, concrete steps, required commands or file edits, validation, and follow-up options.
- **04** Risk context follows the fingerprint: read files, write/modify files, run shell commands; mostly runs locally; usually needs no extra API key.
## Running Rules
- read files, write/modify files, run shell commands; mostly runs locally; usually needs no extra API key.
- Validate with a small sample before expanding scope.
- Return the result, validation criteria, and next iteration options. The source mentions slash commands such as `/goto`, `/help`, `/version`, `/gotolocal`, `/reloadscene`; use them first when your agent supports command triggers.
Name target files or source material, expected output, forbidden changes, and whether network or shell access is allowed. Permission fingerprint: read files, write/modify files, run shell commands.
Start with a small task and check whether the result follows “Sources / Architecture Overview / Component Map”. Inspect diffs, logs, previews, or tests before expanding scope.
Confirm the final output includes a concrete result, evidence, and next action. If it stays generic, tighten inputs, boundaries, and acceptance criteria.
---
name: chat-system
description: Chat system — MVP pattern, message bus decorators, commands, auto-translation, encrypted history…
category: other
source: decentraland/unity-explorer
---
# chat-system
## When to use
- Chat system — MVP pattern, message bus decorators, commands, auto-translation, encrypted history, state machine. Use w…
- Use it when the task has clear inputs, repeatable steps, and validation criteria.
## What to provide
- Target material, scope, expected result, and forbidden changes.
- Whether network, commands, file writes, or external services are allowed.
## Execution rules
- Organize steps around “Sources / Architecture Overview / Component Map” and keep inference separate from source facts.
- read files, write/modify files, run shell commands; mostly runs locally; usually needs no extra API key.
- Validate with a small sample before expanding the task.
## Output requirements
- Return the deliverable, key evidence, validation method, and next action.
- Mark missing information as unknown; do not invent commands, platforms, or dependencies. The author source anchors workflow facts; repository files anchor sources and commands; Fluxly only adds fit, limitations, and quality judgment.
skill "chat-system" {
input -> user goal + target files + boundaries + acceptance criteria
context -> Sources / Architecture Overview / Component Map
rules -> SKILL.md triggers / order / output contract
runtime -> no special runtime | read files, write/modify files, run shell commands | mostly runs locally
guardrails -> usually needs no extra API key + small-sample validation + diff/log review
output -> copyable result + checklist + next iteration
} 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
Decide Fit First
Design Intent
How To Use It
Boundaries And Review