Problem
Chat history is currently keyed only by user (clawpress_chat_history_<user_id>), so each user has exactly one conversation timeline. This blocks thread-based workflows.
Current State
- History persistence:
includes/helpers/class-chat-history-helper.php.
- Chat API:
includes/rest/class-chat-controller.php (/chat/message, /chat/history).
- Panel state tracks
last_history_id, but no thread concept.
Proposed Data Model
Introduce per-user thread IDs and thread metadata:
- Option key for thread list/meta per user (or user meta), e.g.
clawpress_chat_threads_<user_id>.
- History key becomes thread-scoped, e.g.
clawpress_chat_history_<user_id>_<thread_id>.
- Thread metadata fields:
id, title, created_at, updated_at, archived.
Implementation Plan
1) Chat history helper refactor
- Add thread-aware APIs:
get_history_items( ?int $user_id = null, ?string $thread_id = null )
append_history_message(..., ?string $thread_id = null )
clear_history_items(..., ?string $thread_id = null )
- Maintain backward compatibility by defaulting to a
default thread when thread ID not provided.
2) New thread helper
- Add helper for thread CRUD/list/select/archive, with sanitized thread IDs and title generation.
3) REST API updates
- Extend chat endpoints:
POST /chat/message accepts thread_id.
GET /chat/history accepts thread_id.
- Add thread endpoints:
GET /chat/threads
POST /chat/threads
POST /chat/threads/{id} (rename/archive/select metadata update).
4) Panel updates
- Add thread selector in panel.
- New message sends include active
thread_id.
- Persist last active thread in panel state.
5) Migration
- On first use, seed
default thread and map existing single history into that thread.
- No data loss migration path for existing users.
Acceptance Criteria
- A user can create and switch between multiple threads.
- Message history is isolated per thread.
- Existing users retain prior history in
default thread.
- Thread switching does not leak tool events/history across threads.
Test Plan
- Unit tests for thread CRUD helper.
- Unit tests for thread-scoped history persistence.
- REST tests for thread endpoints and
thread_id handling.
- Panel integration tests for switching and send behavior.
Out of Scope
- Cross-thread semantic search.
- Shared threads across users.
Problem
Chat history is currently keyed only by user (
clawpress_chat_history_<user_id>), so each user has exactly one conversation timeline. This blocks thread-based workflows.Current State
includes/helpers/class-chat-history-helper.php.includes/rest/class-chat-controller.php(/chat/message,/chat/history).last_history_id, but no thread concept.Proposed Data Model
Introduce per-user thread IDs and thread metadata:
clawpress_chat_threads_<user_id>.clawpress_chat_history_<user_id>_<thread_id>.id,title,created_at,updated_at,archived.Implementation Plan
1) Chat history helper refactor
get_history_items( ?int $user_id = null, ?string $thread_id = null )append_history_message(..., ?string $thread_id = null )clear_history_items(..., ?string $thread_id = null )defaultthread when thread ID not provided.2) New thread helper
3) REST API updates
POST /chat/messageacceptsthread_id.GET /chat/historyacceptsthread_id.GET /chat/threadsPOST /chat/threadsPOST /chat/threads/{id}(rename/archive/select metadata update).4) Panel updates
thread_id.5) Migration
defaultthread and map existing single history into that thread.Acceptance Criteria
defaultthread.Test Plan
thread_idhandling.Out of Scope