Skip to content

Add bulk thread naming command and automatic naming for new threads#150

Merged
presstab merged 3 commits into
masterfrom
thread_naming
Jun 24, 2026
Merged

Add bulk thread naming command and automatic naming for new threads#150
presstab merged 3 commits into
masterfrom
thread_naming

Conversation

@presstab

Copy link
Copy Markdown
Owner

Overview

This change introduces a new /thread name-all command that allows users to retroactively generate names for existing unnamed threads, and adds automatic thread naming for new chat threads. The implementation uses the existing low_cost_search model profile with a dedicated thread-naming prompt, keeping the cost and latency low while ensuring consistent naming across threads. Additionally, the change includes a bug fix in the TUI thread update event handling and introduces a cap on the input command history size.

What This Means for Users

  • New /thread name-all command: Users with multiple existing unnamed threads (threads created before automatic naming was available) can now retroactively assign meaningful names to all of them in a single operation. The command reports progress and a summary of how many threads were named, skipped, or failed.
  • Automatic thread naming for new threads: Newly created chat threads that are started with a user message are now named automatically using the same model and prompt. This reduces the accumulation of generically named threads (e.g., thread_a1b2c3d4) and makes it easier to find past conversations.
  • Help and documentation updated: The in-app help and docs/threads.md now document the new command, including example output.

A Closer Look at the Changes

New Functionality: Thread Naming

  • /thread name-all subcommand: Added a new subcommand to the /thread command family that iterates over all threads, identifies those with messages but no name, and invokes the LLM to generate a name based on the first user message. The command is registered in the argparse setup, the help text (both formatted and plain variants), and the command catalog shown to users.
  • New prompt file (src/jrdev/prompts/conversation/thread_name.md): Defines the system prompt used to instruct the model to produce a concise thread name (15 letters or fewer) with a structured Thread name: <name> suffix for easy extraction.
  • Shared naming utilities (src/jrdev/services/message_service.py): Extracted two reusable pieces of functionality so that both the existing automatic-naming path and the new bulk command consume the same logic:
    • THREAD_NAME_PATTERN: A regex that captures the Thread name: <name> line from model output.
    • _sanitize_thread_name: Cleans the model output by stripping unsupported characters, collapsing whitespace, and enforcing a maximum length of 15 characters.
  • Automatic naming in the message service: When a new user message is the first message in a thread, the message service now prepends the thread name system prompt to the request, then parses and sanitizes the name from the response after streaming completes. The thread's display name is updated before the response is finalized, ensuring the response text shown to the user does not include the trailing naming line.
  • Helper functions in src/jrdev/commands/thread.py:
    • _thread_needs_name: Filters out the router thread and threads that already have a name.
    • _first_user_message: Returns the first user-authored message in a format safe to send to the LLM, stripping the internal USER_INPUT_PREFIX marker.
    • _extract_thread_name: Robustly extracts a thread name from model output by trying the canonical pattern, an XML-style tag, a "Thread name:" line, or a single-line response as fallbacks.

Bug Fix: TUI Thread Update Event Handling

  • src/jrdev/ui/tui/textual_ui.py: The on_chat_thread_update handler previously assumed the event always referenced the active thread, which caused the chat list to incorrectly mark a non-active thread as active and triggered a chat view reload. The handler now resolves the thread referenced by the event, preserves the user's actual active thread, and only refreshes the chat view when the updated thread is the currently active one.

Code Refinements & Improvements

  • Command history cap (src/jrdev/ui/tui/terminal/input_widget.py): Introduced a MAX_HISTORY = 20 constant applied both when loading history from disk and after each submit, preventing unbounded growth of the persisted history file.
  • Documentation (docs/threads.md): Added a "Naming Existing Threads" section describing the new command along with example output, and noted that the same model and prompt power both automatic and bulk naming.

Generated by JrDev AI using minimax/minimax-m3

presstab added 3 commits June 23, 2026 19:49
Add a constant MAX_HISTORY (20) to cap the number of stored history items, both when loading from file and after appending new submissions.
This commit also fixes a bug in the TUI where updating a non-active thread could incorrectly switch the active chat view.
@presstab presstab merged commit 314867b into master Jun 24, 2026
8 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.

1 participant