[PR #222] [CLOSED] feat(chat): add "Mari is thinking…" indicator for command execution #4513

Closed
opened 2026-10-22 04:08:18 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/222
Author: @cha1latte
Created: 4/24/2026
Status: ❌ Closed

Base: main ← Head: feat/mari-thinking-indicator


📝 Commits (4)

  • 33abfd2 feat(chat): add "Mari is thinking…" indicator for command execution
  • 17b594a fix(chat): address review comments on Mari thinking indicator
  • 4001226 fix(chat): hide Mari indicator immediately on chat switch
  • c1a07d6 chore(chat): skip idle hide timer when pill has no owner

📊 Changes

7 files changed (+222 additions, -0 deletions)

View changed files

📝 CHANGELOG.md (+6 -0)
📝 packages/client/src/components/chat/ChatInput.tsx (+4 -0)
📝 packages/client/src/components/chat/ConversationInput.tsx (+4 -0)
➕ packages/client/src/components/chat/MariThinkingIndicator.tsx (+150 -0)
📝 packages/client/src/hooks/use-generate.ts (+22 -0)
📝 packages/client/src/stores/chat.store.ts (+25 -0)
📝 packages/server/src/routes/generate.routes.ts (+11 -0)

📄 Description

Summary

Adds a small "Mari is thinking…" pill with pulsing dots above the composer whenever Professor Mari is executing one of her embedded commands (create/update character, fetch, create chat, navigate). Shows only in chats where Mari is a participant.

Why

From the Discord feature-request thread — users can't tell whether Mari is still working on a task or stalled, because her commands run after her reply finishes streaming and there's no visible signal during that window. Quote: "I don't know if asking the assistant to work on my cards is happening, or if it's frozen, or what."

Toasts fire only after each command completes, so they're confirmation after-the-fact, not reassurance during-the-wait.

How it works

Layer Change
Server (generate.routes.ts) Emits new SSE events assistant_commands_start (before the command loop) and assistant_commands_end (after), with no filtering — any conversation-mode character's commands emit them.
Client store (chat.store.ts) New commandsExecutingChatId: string | null mirroring the server-side window, set by SSE handlers in use-generate.ts.
Client hook (use-generate.ts) Handles the two new events; also clears on done / error as a safety net.
Component (MariThinkingIndicator.tsx) Self-computes isMariChat from the active chat's characterIds (so the pill is Mari-scoped on the client, keeping the server event neutral). Mounted in both ChatInput (roleplay) and ConversationInput (conversation).

Two notable implementation details:

  • Direct Zustand subscribe, not a selector hook. Simple commands (single DB write) finish faster than a React tick — the start/end state updates would land in the same render batch and the component would never observe the active state. Subscribing to the store directly catches both transitions regardless of batching.
  • 600ms minimum display duration. Without it, fast commands would mount+unmount the pill below perceptual threshold. This way even a 1ms command gives a visible "blip."

Known limitations

  • The event is not Mari-specific on the server. It emits for any conversation-mode character that runs commands (e.g. schedule_update, cross_post). The Mari gate lives on the client, so those cases don't show a pill — but if a future feature wants a generic "assistant is working" indicator for non-Mari commands, the plumbing is already there.
  • The pill is not customizable yet. Keeping this PR focused on the core signal; a user-swappable visual (e.g. the Mari-themed GIF referenced in the Discord thread) can layer on top later with no changes to the event plumbing.
  • If the stream aborts mid-command-loop, the safety clears on done/error handle cleanup, but the assistant_commands_end event won't be received. Behavior: pill disappears when the stream errors, which is correct but means the user doesn't see a natural "finished" signal if the server crashes mid-loop. Acceptable.

Test plan

Manually verified in dev against a Mari conversation chat:

  • Mari chat + action request (create/update/fetch character) → pill appears after stream, disappears after toast
  • Mari chat + pure conversation (no commands) → no pill
  • Non-Mari chat → no pill ever, including when that character's own commands run
  • Multiple commands in one reply → pill stays for the whole window
  • Abort mid-stream → no pill
  • Page reload while pill is showing → no stuck state after reload
  • Chat switch during command execution → pill disappears with the chat context
  • pnpm check clean (lint + production build, no new warnings)
  • pnpm version:check passes
  • pnpm guard:installer-artifacts passes

Screenshot of the pill mid-execution attached.

image

Summary by CodeRabbit

  • New Features
    • Added a "Mari is thinking…" indicator above the chat/composer input that appears while embedded background commands run (character/chat actions and navigation). It provides ARIA-live feedback, enforces a minimum visible duration to avoid flicker, hides immediately when switching chats, and reliably shows/hides during rapid or batched command sequences so the UI no longer appears frozen.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/222 **Author:** [@cha1latte](https://github.com/cha1latte) **Created:** 4/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/mari-thinking-indicator` --- ### 📝 Commits (4) - [`33abfd2`](https://github.com/Pasta-Devs/Marinara-Engine/commit/33abfd27efd0806bca3c03018a0e11605c804e50) feat(chat): add "Mari is thinking…" indicator for command execution - [`17b594a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/17b594ad52190069d01c9e5a774456bd312583ae) fix(chat): address review comments on Mari thinking indicator - [`4001226`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4001226ccc1980a678192ea0f0ea937dead1ea39) fix(chat): hide Mari indicator immediately on chat switch - [`c1a07d6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c1a07d62057b0cb01e718391c9377e42ebd76285) chore(chat): skip idle hide timer when pill has no owner ### 📊 Changes **7 files changed** (+222 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+6 -0) 📝 `packages/client/src/components/chat/ChatInput.tsx` (+4 -0) 📝 `packages/client/src/components/chat/ConversationInput.tsx` (+4 -0) ➕ `packages/client/src/components/chat/MariThinkingIndicator.tsx` (+150 -0) 📝 `packages/client/src/hooks/use-generate.ts` (+22 -0) 📝 `packages/client/src/stores/chat.store.ts` (+25 -0) 📝 `packages/server/src/routes/generate.routes.ts` (+11 -0) </details> ### 📄 Description ## Summary Adds a small "Mari is thinking…" pill with pulsing dots above the composer whenever Professor Mari is executing one of her embedded commands (create/update character, fetch, create chat, navigate). Shows only in chats where Mari is a participant. ## Why From [the Discord feature-request thread](https://discord.com/) — users can't tell whether Mari is still working on a task or stalled, because her commands run *after* her reply finishes streaming and there's no visible signal during that window. Quote: *"I don't know if asking the assistant to work on my cards is happening, or if it's frozen, or what."* Toasts fire only after each command completes, so they're confirmation after-the-fact, not reassurance during-the-wait. ## How it works | Layer | Change | |---|---| | Server (`generate.routes.ts`) | Emits new SSE events `assistant_commands_start` (before the command loop) and `assistant_commands_end` (after), with no filtering — any conversation-mode character's commands emit them. | | Client store (`chat.store.ts`) | New `commandsExecutingChatId: string \| null` mirroring the server-side window, set by SSE handlers in `use-generate.ts`. | | Client hook (`use-generate.ts`) | Handles the two new events; also clears on `done` / `error` as a safety net. | | Component (`MariThinkingIndicator.tsx`) | Self-computes `isMariChat` from the active chat's `characterIds` (so the pill is Mari-scoped on the client, keeping the server event neutral). Mounted in both `ChatInput` (roleplay) and `ConversationInput` (conversation). | Two notable implementation details: - **Direct Zustand subscribe, not a selector hook.** Simple commands (single DB write) finish faster than a React tick — the start/end state updates would land in the same render batch and the component would never observe the active state. Subscribing to the store directly catches both transitions regardless of batching. - **600ms minimum display duration.** Without it, fast commands would mount+unmount the pill below perceptual threshold. This way even a 1ms command gives a visible "blip." ## Known limitations - The event is **not** Mari-specific on the server. It emits for any conversation-mode character that runs commands (e.g. `schedule_update`, `cross_post`). The Mari gate lives on the client, so those cases don't show a pill — but if a future feature wants a generic "assistant is working" indicator for non-Mari commands, the plumbing is already there. - The pill is not customizable yet. Keeping this PR focused on the core signal; a user-swappable visual (e.g. the Mari-themed GIF referenced in the Discord thread) can layer on top later with no changes to the event plumbing. - If the stream aborts mid-command-loop, the safety clears on `done`/`error` handle cleanup, but the `assistant_commands_end` event won't be received. Behavior: pill disappears when the stream errors, which is correct but means the user doesn't see a natural "finished" signal if the server crashes mid-loop. Acceptable. ## Test plan Manually verified in dev against a Mari conversation chat: - [x] Mari chat + action request (create/update/fetch character) → pill appears after stream, disappears after toast - [x] Mari chat + pure conversation (no commands) → no pill - [x] Non-Mari chat → no pill ever, including when that character's own commands run - [x] Multiple commands in one reply → pill stays for the whole window - [x] Abort mid-stream → no pill - [x] Page reload while pill is showing → no stuck state after reload - [x] Chat switch during command execution → pill disappears with the chat context - [x] `pnpm check` clean (lint + production build, no new warnings) - [x] `pnpm version:check` passes - [x] `pnpm guard:installer-artifacts` passes Screenshot of the pill mid-execution attached. <img width="1046" height="117" alt="image" src="https://github.com/user-attachments/assets/8b4cfa69-c96f-4369-8b1a-ba06348cf15d" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a "Mari is thinking…" indicator above the chat/composer input that appears while embedded background commands run (character/chat actions and navigation). It provides ARIA-live feedback, enforces a minimum visible duration to avoid flicker, hides immediately when switching chats, and reliably shows/hides during rapid or batched command sequences so the UI no longer appears frozen. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:08:18 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#4513
No description provided.