Skip to content

feat: Smart Context plugin — topic bubbles + embedding-based context filtering - #45

Merged
ARC345 merged 21 commits into
mainfrom
feature/smart-context-plugin
Mar 1, 2026
Merged

ARC345 merged 21 commits into
mainfrom
feature/smart-context-plugin

Conversation

@ARC345

@ARC345 ARC345 commented Mar 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds a Smart Context plugin that extracts topics from chat conversations via LLM and displays them as a clickable bubble cloud in a side panel
  • Clicking topic bubbles activates an embedding-based filter that limits which messages are injected into the LLM pipeline as history (threshold-based cosine similarity)
  • "Instructions & Preferences" messages (short directives like "be concise") are identified by the LLM and always injected regardless of filter state
  • Chat messages matching the active filter get a blue left-border highlight in the main chat view

New files

File Purpose
example-vault/plugins/smart_context/main.py Full plugin: pipeline subscribers, commands, embedding cache usage
example-vault/plugins/smart_context/embedding_cache.py File-backed JSON embedding cache keyed by {msg_id}:{content_hash}
example-vault/plugins/smart_context/panel.html Bubble cloud UI with similarity toggle and N-of-M status line

Modified files

File Change
sidecar/services/llm_service.py Added embed() method via LiteLLM aembedding
src/vault/chat/chat.js Added setupSmartContextEventListeners() for message highlighting
src/styles/styles.css Added .sc-highlight class
example-vault/.vault.toml Added explicit smart_context config defaults

Test plan

  • 158 tests pass (pixi run test)
  • Open example-vault, send a few messages on different topics
  • Smart Context panel appears on right side with topic bubbles after first response
  • Clicking a bubble highlights matching messages in chat and filters LLM context
  • "Instructions & Preferences" bar shows count of always-on messages
  • Similarity toggle disables filtering (bubbles become visualization-only)
  • Status line shows "N of M messages in context" when filter active

🤖 Generated with Claude Code

ARC345 and others added 21 commits March 1, 2026 12:23
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Implement _compute_relevant_ids() and _on_pipeline_context() to filter
pipeline chat history using cosine similarity against active topic
embeddings. Sticky messages are always preserved; if nothing passes the
threshold the full history is kept as a fallback. Adds 4 tests (17 total).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…_mode

Implements the three stub command methods and adds _emit_highlight_ids.
set_filter updates active_topics and emits filter_changed; get_topics
loads chat data via memory.load_chat; set_similarity_mode toggles
embedding search and clears the filter when disabled.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds .sc-highlight CSS class and two window event listeners in chat.js
(setupSmartContextEventListeners) so Smart Context filter events visually
highlight matching messages via a blue left-border accent. Also fixes a
variable shadowing lint issue in panel.html (e -> err in catch handler).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ory_fallback tests

The smart_context plugin registers a pipeline.output subscriber that spawns a
background asyncio task (_run_topic_extraction) after every LLM response. In the
test environment the memory plugin is live, so memory.load_chat succeeds and
_run_topic_extraction proceeds to call LLMService.complete with the topic
extraction prompt. This overwrites mock_instance.complete.call_args, making the
test's assertion about which messages were sent to the chat completion call fail.

Fix: patch _run_topic_extraction to a no-op AsyncMock on the smart_context
plugin instance before the test's chat_send calls, so background extraction
cannot consume mock calls or corrupt call_args.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…e writes

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ARC345
ARC345 merged commit 3ab6926 into main Mar 1, 2026
2 checks passed
@ARC345
ARC345 deleted the feature/smart-context-plugin branch March 1, 2026 09:53
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