Skip to content

feat: add thread deletion (MCP tool + REST API + web UI)#5

Merged
Killea merged 2 commits intoKillea:mainfrom
bertheto:feat/thread-delete
Feb 28, 2026
Merged

feat: add thread deletion (MCP tool + REST API + web UI)#5
Killea merged 2 commits intoKillea:mainfrom
bertheto:feat/thread-delete

Conversation

@bertheto
Copy link
Contributor

Summary

Adds the ability to permanently delete a thread and all its messages,
consistently across all interaction surfaces.

Currently, threads can only be archived or closed (reversible). This PR
adds irreversible deletion for clean-up use cases (test threads, accidental
threads, stale content).

Changes

src/db/crud.pythread_delete()

  • Deletes messages before thread (FK constraint)
  • Single transaction with rollback on error
  • Returns audit dict {thread_id, topic, message_count} or None if not found
  • Emits thread.deleted SSE event

src/mcp_server.pythread_delete tool

  • Requires confirm: true parameter (safeguard against accidental deletion)
  • Description explicitly contrasts with thread_archive for reversible removal

src/tools/dispatch.pyhandle_thread_delete()

  • Returns structured error if confirm != true
  • Returns audit info on success

src/main.pyDELETE /api/threads/{thread_id}

  • Returns {ok: true, deleted: {thread_id, topic, message_count}}
  • Returns 404 if thread not found

src/static/index.html — Web UI

  • Delete button in thread context menu (red, separated by <hr>)
  • Native <dialog> confirmation showing topic + message count
  • SSE handler for thread.deleted clears active message pane

Design Notes

  • confirm=true on MCP tool: Standard MCP pattern for destructive actions,
    prevents accidental deletion by AI agents that auto-call tools.
  • Native <dialog>: No external deps, accessible, keyboard-navigable.
  • No cascade FK: SQLite FK cascade is opt-in; explicit deletion order
    (messages → thread) is safer and more portable.

Test

End-to-end (HTTP):

# Create thread, post message, delete
```t = Invoke-RestMethod http://localhost:39765/api/threads -Method POST -ContentType application/json -Body '{topic:test,initiator:me}'
Invoke-RestMethod http://localhost:39765/api/threads/```(```t.id)/messages -Method POST -ContentType application/json -Body '{author:me,content:hi}'
Invoke-RestMethod http://localhost:39765/api/threads/```(```t.id) -Method DELETE
# → {ok: True, deleted: {topic: test, message_count: 1}}

bertheto and others added 2 commits February 27, 2026 18:32
Permanently delete a thread and all its messages via MCP tool,
REST API, and the web console UI.

- CRUD: thread_delete() with cascade (messages first), single transaction,
  rollback on error, returns audit dict {thread_id, topic, message_count}
- MCP tool: thread_delete with confirm=true safeguard; description explicitly
  warns vs thread_archive for reversible removal
- REST API: DELETE /api/threads/{thread_id} returns {ok, deleted} with audit info
- Web UI: Delete button in context menu (destructive red styling, visual separator),
  native <dialog> showing topic + message count, SSE handler for thread.deleted
  clears active pane when current thread is deleted
- Tests: 9 unit tests covering CRUD behaviour, MCP dispatch, confirm guard

Made-with: Cursor
@Killea Killea merged commit c587c60 into Killea:main Feb 28, 2026
1 check failed
Killea added a commit that referenced this pull request Feb 28, 2026
- Delete duplicate thread_delete function in crud.py (old version returning bool)
- Delete duplicate api_thread_delete function in main.py (old version with simple response)
- Keep only PR #5 versions that return full audit information
- Resolve function redefinition conflicts from merge
Killea added a commit that referenced this pull request Feb 28, 2026
…NewMessages

- Delete incorrect return window.AcbChat.selectThread() call that was causing ReferenceError
- Delete duplicate loadNewMessages function that was trying to call window.AcbChat.loadNewMessages
- Restore proper function structure: selectThread and loadNewMessages should directly implement functionality
- Resolve merge conflict from PR #5 that introduced these invalid calls
Killea added a commit that referenced this pull request Feb 28, 2026
… calls

- Fix selectThread: remove nested loadNewMessages function, make it independent
- Fix sendMessage: implement directly instead of calling window.AcbChat.sendMessage
- Fix handleKey: implement directly instead of calling window.AcbChat.handleKey
- Fix refreshAgents: implement directly instead of calling window.AcbAgents.refreshAgents
- Remove all erroneous window.Acb* calls that were causing ReferenceError
- Resolve merge conflict issues from PR #5 that introduced duplicate/invalid function structures
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