Skip to content

feat: Add /stop and /start commands for telegram bot (Issue #1081)#1111

Merged
konard merged 11 commits intomainfrom
issue-1081-fc44dff2430e
Mar 31, 2026
Merged

feat: Add /stop and /start commands for telegram bot (Issue #1081)#1111
konard merged 11 commits intomainfrom
issue-1081-fc44dff2430e

Conversation

@konard
Copy link
Copy Markdown
Contributor

@konard konard commented Jan 11, 2026

Summary

Add /stop and /start commands for the Telegram bot that allow chat owners to control whether the bot accepts new tasks in their chat.

Key features:

  • /stop command puts the bot in read-only mode for the chat (owner only)
  • /stop <reason> - Optional reason text shown in rejection messages
  • /stop "<reason>" and /stop '<reason>' - Quotes are automatically stripped
  • /start command resumes accepting tasks (owner only)
  • Only the chat creator can use these commands (not admins)
  • When stopped: /solve, /hive, and /merge are rejected with consistent message style
  • Rejection uses the same style as queue rejected mode: ❌ {Command} command rejected. 🚫 Reason: ...
  • Default reason: This bot is currently not accepting new tasks.
  • Read-only commands (/help, /limits, /version) remain available
  • Existing queue items continue to process (graceful stop)
  • State is per-chat and resets on bot restart

Implementation Details

  1. New module: src/telegram-start-stop-command.lib.mjs

    • Per-chat stop state management using Map<chatId, StopInfo>
    • StopInfo includes: stoppedAt, stoppedBy, and optional reason
    • Exports: isChatStopped(), setChatStopped(), getChatStopInfo(), getStoppedChats(), getStoppedChatRejectMessage(), DEFAULT_STOP_REASON
    • Owner-only access control via extracted validateOwnerCommand() helper (reduces duplication)
    • Quote stripping for reason: strips "..." and '...'
  2. Changes to telegram-bot.mjs:

    • Import and use isChatStopped check in /solve and /hive handlers
    • Rejection uses safeReply with getStoppedChatRejectMessage(chatId, 'Solve') for consistent style
    • Register /start and /stop commands from the new module
    • Update /help to show stopped status with reason (or default reason)
    • Pass isChatStopped and getStoppedChatRejectMessage to merge command module
  3. Changes to telegram-merge-command.lib.mjs:

    • Accept optional isChatStopped and getStoppedChatRejectMessage in options
    • Reject /merge commands when chat is stopped
  4. Test script: experiments/test-start-stop-command.mjs

    • Tests all state management functions (17 tests)
    • Tests for reason support, quote stripping, reject message format, DEFAULT_STOP_REASON

Test Plan

  • Unit tests pass (node experiments/test-start-stop-command.mjs)
  • Linting passes (npm run lint)
  • Formatting passes (npm run format:check)
  • Duplication check passes (npm run check:duplication)
  • Manual testing in Telegram group:
    • Only chat creator can use /stop
    • /stop Maintenance shows reason in confirmation and rejection
    • /stop "Maintenance" strips quotes
    • /solve and /hive rejected with ❌ Solve/Hive command rejected. 🚫 Reason: ...
    • /merge rejected when stopped
    • /help shows stopped status with reason
    • Only chat creator can use /start
    • Commands work again after /start

Fixes #1081


🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #1081
@konard konard self-assigned this Jan 11, 2026
konard and others added 4 commits January 11, 2026 05:29
Create telegram-start-stop-command.lib.mjs module with:
- Per-chat stop state management using Map
- isChatStopped() and setChatStopped() for state control
- getChatStopInfo() and getStoppedChats() for status queries
- Owner-only access control (creator, not admins)
- Graceful stop: existing queue items continue to process

This is the core module for issue #1081.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Changes to telegram-bot.mjs:
- Import isChatStopped and getChatStopInfo from new module
- Add stop check to /solve command (rejects if chat stopped)
- Add stop check to /hive command (rejects if chat stopped)
- Register start/stop commands from new module
- Update /help to show stopped status when applicable
- Add /stop and /start to help command list

Fixes #1081

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add test-start-stop-command.mjs to experiments folder with tests for:
- Initial state (no chats stopped)
- Stopping a chat
- Getting stop info
- Per-chat isolation
- Getting all stopped chats
- Starting (un-stopping) a chat
- Multiple chats can be stopped independently

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard konard changed the title [WIP] /stop command feat: Add /stop and /start commands for telegram bot (Issue #1081) Jan 11, 2026
@konard konard marked this pull request as ready for review January 11, 2026 04:30
konard and others added 3 commits January 11, 2026 05:33
- Format telegram-start-stop-command.lib.mjs with prettier
- Compact command registration in telegram-bot.mjs to stay under 1500 lines
- telegram-bot.mjs now at 1487 lines (was 1502)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard
Copy link
Copy Markdown
Contributor Author

konard commented Jan 11, 2026

⚠️ Solution Draft Finished with Errors

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $7.231747 USD
  • Calculated by Anthropic: $0.000000 USD
  • Difference: $-7.231747 (-100.00%)

Note: The session encountered errors during execution, but some work may have been completed. Please review the changes carefully.

📎 Log file uploaded as Gist (1505KB)
🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Copy Markdown
Contributor Author

konard commented Jan 19, 2026

Resolve conflicts, and add optional reason support for /stop command (any text after the command /stop ). So all other write commands will show this reason, if it is provided.

@konard konard marked this pull request as draft January 19, 2026 22:17
@konard
Copy link
Copy Markdown
Contributor Author

konard commented Jan 19, 2026

🤖 AI Work Session Started

Starting automated work session at 2026-01-19T22:17:36.170Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait working session to finish, and provide your feedback.

konard and others added 2 commits January 19, 2026 23:21
- Add reason parameter to setChatStopped() function
- Parse reason text from /stop command (text after "/stop ")
- Display reason in /solve and /hive rejection messages
- Display reason in /help stopped status section
- Display reason when /stop is called on already-stopped chat
- Add tests for reason functionality (tests 10-13)

Resolves conflict with main branch by merging accept_invites command.

Fixes #1081

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…count

- Add getStoppedChatRejectMessage() helper to start-stop module
- Use helper in /solve and /hive handlers to reduce code duplication
- Simplify verbose logging with VERBOSE && console.log() pattern
- Reduce telegram-bot.mjs from 1534 to 1488 lines (under 1500 limit)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard
Copy link
Copy Markdown
Contributor Author

konard commented Jan 19, 2026

✅ Resolved

I've addressed all the feedback from the latest comments:

Merge conflicts resolved

Optional reason support for /stop command

  • /stop now accepts an optional reason: /stop Maintenance in progress
  • The reason is stored in the stop info and displayed in:
    • /stop confirmation message
    • /solve and /hive rejection messages when the bot is stopped
    • /help stopped status section
    • "Already stopped" message when /stop is called again

Code quality

  • Extracted getStoppedChatRejectMessage() helper to reduce code duplication
  • Reduced telegram-bot.mjs from 1534 to 1488 lines (under the 1500 limit)
  • All local tests pass (npm run test + experiments/test-start-stop-command.mjs)
  • All CI checks are passing

Example usage

/stop                           → Stops bot with no reason
/stop Maintenance in progress   → Stops bot with reason "Maintenance in progress"

When stopped with a reason, rejection messages will show:

❌ This bot is currently stopped in this chat and not accepting new tasks.

*Reason:* Maintenance in progress

Use /start to resume (chat owner only).

🤖 Generated with Claude Code

@konard konard marked this pull request as ready for review January 19, 2026 22:31
@konard
Copy link
Copy Markdown
Contributor Author

konard commented Jan 19, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $7.365753 USD
  • Calculated by Anthropic: $5.103654 USD
  • Difference: $-2.262099 (-30.71%)
    📎 Log file uploaded as Gist (1390KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Copy Markdown
Contributor Author

konard commented Mar 31, 2026

We now have rejected mode for queue handling, we just make use the same style of output all tasks using /solve or /hive are rejected, with default reason: This bot is currently not accepting new tasks., and also /stop <reason> and /stop "<reason>" and /stop '<reason>' should all work.

Double check the latest changed in default branch, resolve conflicts.

We also need to ensure all changes are correct, consistent, validated, tested, logged and fully meet all discussed requirements (check issue description and all comments in issue and in pull request). Ensure all CI/CD checks pass.

@konard konard marked this pull request as draft March 31, 2026 16:06
@konard
Copy link
Copy Markdown
Contributor Author

konard commented Mar 31, 2026

🤖 AI Work Session Started

Starting automated work session at 2026-03-31T16:06:22.715Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait for the session to finish, and provide your feedback.

…ipping

- Resolve merge conflicts with latest main branch (v1.41.0)
- Match queue rejected mode output style: ❌ {Command} command rejected. 🚫 Reason: ...
- Default stop reason: "This bot is currently not accepting new tasks."
- Strip surrounding quotes from /stop reason: /stop "reason", /stop 'reason'
- Add /merge command rejection when chat is stopped (issue #1081)
- Extract validateOwnerCommand helper to reduce code duplication
- Add tests for reject message format, DEFAULT_STOP_REASON, and command name

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@konard konard marked this pull request as ready for review March 31, 2026 16:25
@konard
Copy link
Copy Markdown
Contributor Author

konard commented Mar 31, 2026

✅ Resolved

Addressed all feedback from the latest comment:

Merge conflicts resolved

  • Merged latest main branch (v1.41.0, 582 files changed) into the feature branch
  • Resolved 4 conflict regions in telegram-bot.mjs (imports, help text, isGroupChat, command registration)

Rejection style matches queue rejected mode

  • /solve, /hive, and /merge now use the same output style as check.rejected:
    ❌ Solve command rejected.
    
    🚫 Reason: This bot is currently not accepting new tasks.
    
    Use /start to resume (chat owner only).
    
  • Default reason: This bot is currently not accepting new tasks.
  • Custom reason example: /stop Maintenance🚫 Reason: Maintenance

Quote stripping for /stop reason

  • /stop <reason> → reason as-is
  • /stop "reason text" → strips double quotes
  • /stop 'reason text' → strips single quotes
  • Also handles @botname suffix: /stop@botname "reason"

/merge command also rejected when stopped

  • Added isChatStopped and getStoppedChatRejectMessage to merge command module
  • Shows: ❌ Merge command rejected. 🚫 Reason: ...

Code quality improvements

  • Extracted validateOwnerCommand() helper in start-stop module to reduce duplication (10.93% < 11% threshold)
  • telegram-bot.mjs at 1497 lines (under 1500 limit)
  • All CI checks passing ✅
  • 17 experiment tests pass

🤖 Generated with Claude Code

@konard
Copy link
Copy Markdown
Contributor Author

konard commented Mar 31, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $5.929998
  • Calculated by Anthropic: $5.929998 USD
  • Difference: $0.000000 (0.00%)

📊 Context and tokens usage:

Claude Opus 4.6:

  • Max context window: 102.9K / 1M input tokens (10%)
  • Max output tokens: 28.7K / 128K output tokens (22%)

Total input tokens: 95.5K + 8.8M cached
Total output tokens: 28.7K output
Cost: $5.734752

Claude Haiku 4.5:

  • Context window: 992.9K / 200K tokens (496%)
  • Max output tokens: 5.4K / 64K output tokens (8%)

Total input tokens: 60.7K + 932.2K cached
Total output tokens: 5.4K output
Cost: $0.195246

🤖 Models used:

  • Tool: Anthropic Claude Code
  • Requested: opus
  • Main model: Claude Opus 4.6 (claude-opus-4-6)
  • Additional models:
    • Claude Haiku 4.5 (claude-haiku-4-5-20251001)

📎 Log file uploaded as Gist (4130KB)


Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Copy Markdown
Contributor Author

konard commented Mar 31, 2026

✅ Ready to merge

This pull request is now ready to be merged:

  • All CI checks have passed
  • No merge conflicts
  • No pending changes

Monitored by hive-mind with --auto-restart-until-mergeable flag

@konard konard merged commit 8f10dea into main Mar 31, 2026
21 checks passed
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.

/stop command

1 participant