Skip to content

feat(discord): add /status command for thread inspection#28

Open
jettcc wants to merge 2 commits intoDoctor-wu:mainfrom
jettcc:feat/status
Open

feat(discord): add /status command for thread inspection#28
jettcc wants to merge 2 commits intoDoctor-wu:mainfrom
jettcc:feat/status

Conversation

@jettcc
Copy link
Copy Markdown
Contributor

@jettcc jettcc commented Mar 12, 2026

Summary

  • Add /status slash command to the Discord adapter
  • Displays current thread configuration and session state at a glance

Motivation

When working across multiple threads, it's hard to know:

  • Which backend/model is active in a given thread
  • Whether a previous session is still resumable or has been invalidated
  • What the last task was (useful for context when returning to a thread)

/status surfaces all of this in a single ephemeral reply.

Output

Thread Status

  • Backend: claude
  • Model: sonnet
  • Effort: backend default
  • Working directory: /Users/xxx/project
  • Session: 🔵 Idle (session ready to resume)
  • Last task: ✅ Refactored the auth module and added unit tests
CleanShot 2026-03-12 at 15 43 49@2x

Session states:

  • 🟢 Running — agent is currently executing
  • 🔵 Idle — session is confirmed and ready to resume
  • 🔴 Invalidated — session has expired, next run starts fresh
  • No session — brand new thread

Summary by CodeRabbit

  • New Features

    • Added a Discord "status" command that shows thread session info: current status, backend/model details, working directory, and last task summary.
  • Tests

    • Added test mocks for the status command to enable reliable testing of status behavior and responses.

Shows backend, model, effort, working directory, session state, and
last task summary for the current thread. Useful when switching between
multiple threads or checking whether a session is still resumable.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 12, 2026

📝 Walkthrough

Walkthrough

A new Discord "status" slash command and handler were added, registered in the bot index, and a test mock for the status module was included to simulate command behavior in tests.

Changes

Cohort / File(s) Summary
Status Command Implementation
packages/discord/src/commands/status.ts
Adds statusCommand (SlashCommandBuilder) and handleStatusCommand(interaction) which validates thread context, reads thread-specific in-memory maps (session/backend/model/working-dir/status), formats session status and last-task summaries (with emoji indicators), and replies ephemerally.
Command Registration
packages/discord/src/index.ts
Imports and registers the new status command and handler in commandHandlers and commandDefinitions, enabling the command at runtime.
Test Mocks
packages/discord/src/__tests__/index.test.ts
Adds mocks for the status command module: statusCommand.toJSON() and a mock handleStatusCommand to support tests.

Sequence Diagram

sequenceDiagram
    actor User
    participant Discord as Discord Interaction
    participant Handler as handleStatusCommand
    participant Maps as In-Memory Maps
    participant Formatter as Format Helpers
    participant Bot as Bot Reply

    User->>Discord: /status (in thread)
    Discord->>Handler: ChatInputCommandInteraction
    Handler->>Handler: Validate thread context
    alt Not in thread
        Handler->>Bot: Reply with error (ephemeral)
        Bot->>User: Error message
    else In thread
        Handler->>Maps: Query session/backend/model/working-dir/status
        Maps-->>Handler: Thread-specific data
        Handler->>Formatter: formatSessionStatus()
        Formatter-->>Handler: Status with emoji
        Handler->>Formatter: formatLastTask()
        Formatter-->>Handler: Task summary or null
        Handler->>Handler: Aggregate report
        Handler->>Bot: Reply with formatted report (ephemeral)
        Bot->>User: Status report
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 A status command hops into view,
It peeks in threads to see what's new,
Emojis blink, last tasks chime,
A rabbit logs the running time—
Tiny hops, big clarity too!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding a /status command to Discord for thread inspection, which aligns with the detailed implementation across three files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Owner

@Doctor-wu Doctor-wu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

PR #28: feat(discord): add /status command for thread inspection
Author: jettcc | Branch: feat/status → main | +95 -0 | 3 files

新增 /status slash command,在 thread 内显示当前 backend、model、effort、cwd、session 状态和上次任务摘要。ephemeral reply,只有调用者可见。


⚠️ WARNING

1. conversationEffort 导入需确认 core 已导出

status.ts@agent-im-relay/core 导入了 conversationEffort,需要确认该 Map 已在 core 包中导出,否则运行时 import 报错。

2. threadContinuationSnapshots 的字段类型保障

snapshot.taskSummarysnapshot.whyStopped 没有在这个 PR 里定义类型,假设 core 包已有。建议确认字段名和类型一致。


💬 NIT

3. 缺少 /status 命令自身的单元测试

测试文件只加了 mock,没有测试 handleStatusCommand 本身。建议至少覆盖:

  • 非 thread 中调用 → ephemeral 提示
  • thread 中调用 → 正确拼装状态信息
  • 有 lastTask vs 无 lastTask

4. stopReasonEmoji 可以提取为模块级常量

每次调用 formatLastTask 都重新创建对象,提到模块顶层更干净。

5. backend 默认值硬编码 claude (default) 可能不准确

const backend = conversationBackend.get(id) ?? 'claude (default)'

如果系统默认 backend 不是 claude,这里会误导用户。建议改为 'not set' 或从配置读取实际默认值。


✅ 亮点

  • 功能实用,多 thread 工作时快速了解当前状态
  • ephemeral reply 不污染 thread 对话
  • session 状态用 emoji 区分,一目了然
  • taskSummary 截断到 120 字符,防止消息过长

✅ Review 通过,建议补上单元测试和修正 backend 默认值显示。不阻塞合并。

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/discord/src/__tests__/index.test.ts (1)

152-155: Consider adding a direct /status routing assertion test.

Right now this mock is added, but there’s no explicit test that a status chat-input interaction invokes handleStatusCommand. Adding one would prevent silent handler-map regressions.

Suggested test addition
 import { handleDiscordMessageCreate } from '../index';
 import { handleSkillAutocomplete } from '../commands/skill';
+import { handleStatusCommand } from '../commands/status';
 import { config as discordConfig } from '../config';

+it('routes /status chat-input interactions to the status handler', async () => {
+  const interaction = {
+    isChatInputCommand: () => true,
+    isAutocomplete: () => false,
+    commandName: 'status',
+  } as any;
+
+  await interactionCreateHandler?.(interaction);
+
+  expect(handleStatusCommand).toHaveBeenCalledWith(interaction);
+});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/discord/src/__tests__/index.test.ts` around lines 152 - 155, Add a
unit test that verifies a chat-input interaction with commandName "status"
routes to the mocked handler: create a fake interaction object representing a
chat-input `/status` (matching whatever router entry point you already call in
index.test.ts), invoke the message/interaction dispatcher used in the tests (the
same function that currently processes other interactions in the file), and
assert that the mocked handleStatusCommand was called; reference the mocked
symbols statusCommand and handleStatusCommand so the test explicitly protects
against handler-map regressions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/discord/src/__tests__/index.test.ts`:
- Around line 152-155: Add a unit test that verifies a chat-input interaction
with commandName "status" routes to the mocked handler: create a fake
interaction object representing a chat-input `/status` (matching whatever router
entry point you already call in index.test.ts), invoke the message/interaction
dispatcher used in the tests (the same function that currently processes other
interactions in the file), and assert that the mocked handleStatusCommand was
called; reference the mocked symbols statusCommand and handleStatusCommand so
the test explicitly protects against handler-map regressions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 923dc5f6-62a6-45db-8f63-efd87cbf5c7e

📥 Commits

Reviewing files that changed from the base of the PR and between fce4245 and 0805a53.

📒 Files selected for processing (2)
  • packages/discord/src/__tests__/index.test.ts
  • packages/discord/src/index.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/discord/src/index.ts

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.

2 participants